diff --git a/examples/sql/cachedtable/tableeditor.cpp b/examples/sql/cachedtable/tableeditor.cpp index 71e441486d..95c3047c76 100644 --- a/examples/sql/cachedtable/tableeditor.cpp +++ b/examples/sql/cachedtable/tableeditor.cpp @@ -85,9 +85,9 @@ TableEditor::TableEditor(const QString &tableName, QWidget *parent) //! [2] //! [3] - connect(submitButton, SIGNAL(clicked()), this, SLOT(submit())); - connect(revertButton, SIGNAL(clicked()), model, SLOT(revertAll())); - connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); + connect(submitButton, &QPushButton::clicked, this, &TableEditor::submit); + connect(revertButton, &QPushButton::clicked, model, &QSqlTableModel::revertAll); + connect(quitButton, &QPushButton::clicked, this, &TableEditor::close); //! [3] //! [4] diff --git a/examples/sql/cachedtable/tableeditor.h b/examples/sql/cachedtable/tableeditor.h index 6544276cbe..727aa88ab3 100644 --- a/examples/sql/cachedtable/tableeditor.h +++ b/examples/sql/cachedtable/tableeditor.h @@ -65,7 +65,7 @@ class TableEditor : public QWidget Q_OBJECT public: - explicit TableEditor(const QString &tableName, QWidget *parent = 0); + explicit TableEditor(const QString &tableName, QWidget *parent = nullptr); private slots: void submit(); diff --git a/examples/sql/connection.h b/examples/sql/connection.h index 3bedf4b061..482feff5b4 100644 --- a/examples/sql/connection.h +++ b/examples/sql/connection.h @@ -70,12 +70,12 @@ static bool createConnection() QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(":memory:"); if (!db.open()) { - QMessageBox::critical(0, qApp->tr("Cannot open database"), - qApp->tr("Unable to establish a database connection.\n" - "This example needs SQLite support. Please read " - "the Qt SQL driver documentation for information how " - "to build it.\n\n" - "Click Cancel to exit."), QMessageBox::Cancel); + QMessageBox::critical(nullptr, QObject::tr("Cannot open database"), + QObject::tr("Unable to establish a database connection.\n" + "This example needs SQLite support. Please read " + "the Qt SQL driver documentation for information how " + "to build it.\n\n" + "Click Cancel to exit."), QMessageBox::Cancel); return false; } diff --git a/examples/sql/doc/src/drilldown.qdoc b/examples/sql/doc/src/drilldown.qdoc index 1fcac41eeb..e8841d2013 100644 --- a/examples/sql/doc/src/drilldown.qdoc +++ b/examples/sql/doc/src/drilldown.qdoc @@ -172,11 +172,20 @@ \snippet drilldown/informationwindow.cpp 4 Finally, we connect the "something's changed" signals in the - editors to our custom \c enableButtons() slot, enabling the users - to either submit or revert their changes. We add all the widgets - into a layout, store the item ID and the name of the displayed - image file for future reference, and set the window title and - initial size. + editors to our custom \c enableButtons slot, enabling the users + to either submit or revert their changes. + We need to use lambdas for connecting the \c enableButtons slot + because its signature does not match \c QTextEdit::textChanged + and \c QComboBox::currentIndexChanged. + Since the latter has another overload with the signature + \c {const QString &} and the selected signal would be ambiguous, + we need to use \c QOverload::of to select a specific overload + for \c currentIndexChanged. + + We add all the widgets into a layout, store the item ID and the + name of the displayed image file for future reference, and set + the window title and initial size. + Note that we also set the Qt::Window window flag to indicate that our widget is in fact a window, with a window system frame and a @@ -389,19 +398,21 @@ \snippet drilldown/view.cpp 6 The \c showInformation() function is given an \c ImageItem object - as argument, and starts off by extracting the item's item - ID. Then it determines if there already is created an information - window for this location. If it is, and the window is visible, it - ensures that the window is raised to the top of the widget stack - and activated. If the window exists but is hidden, calling its \l - {QWidget::}{show()} slot gives the same result. + as argument, and starts off by extracting the item's item ID. + Then it determines if there already is created an information + window for this location. If no window for the given location exists, we create one by passing the item ID, a pointer to the model, and our view as a parent, to the \c InformationWindow constructor. Note that we connect the information window's \c imageChanged() signal to \e this widget's \c updateImage() slot, before we give it a suitable position and add it to the list of existing windows. + If there is a window for the given location, and that window is + visible, it ensures that the window is raised to the top of the + widget stack and activated. If it is hidden, calling its \l + {QWidget::}{show()} slot gives the same result. + \snippet drilldown/view.cpp 7 diff --git a/examples/sql/drilldown/imageitem.cpp b/examples/sql/drilldown/imageitem.cpp index 4e440fc786..04ec614755 100644 --- a/examples/sql/drilldown/imageitem.cpp +++ b/examples/sql/drilldown/imageitem.cpp @@ -60,8 +60,8 @@ ImageItem::ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent) timeLine.setDuration(150); timeLine.setFrameRange(0, 150); - connect(&timeLine, SIGNAL(frameChanged(int)), this, SLOT(setFrame(int))); - connect(&timeLine, SIGNAL(finished()), this, SLOT(updateItemPosition())); + connect(&timeLine, &QTimeLine::frameChanged, this, &ImageItem::setFrame); + connect(&timeLine, &QTimeLine::finished, this, &ImageItem::updateItemPosition); adjust(); } @@ -116,7 +116,7 @@ void ImageItem::adjust() //! [4] //! [5] -int ImageItem::id() +int ImageItem::id() const { return recordId; } diff --git a/examples/sql/drilldown/imageitem.h b/examples/sql/drilldown/imageitem.h index 4f773a6dfc..abb9103c7e 100644 --- a/examples/sql/drilldown/imageitem.h +++ b/examples/sql/drilldown/imageitem.h @@ -60,10 +60,10 @@ class ImageItem : public QObject, public QGraphicsPixmapItem Q_OBJECT public: - ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent = 0); + ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent = nullptr); void adjust(); - int id(); + int id() const; protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; diff --git a/examples/sql/drilldown/informationwindow.cpp b/examples/sql/drilldown/informationwindow.cpp index 2536b0ca91..0007432672 100644 --- a/examples/sql/drilldown/informationwindow.cpp +++ b/examples/sql/drilldown/informationwindow.cpp @@ -84,10 +84,12 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *items, //! [3] //! [4] - connect(descriptionEditor, SIGNAL(textChanged()), - this, SLOT(enableButtons())); - connect(imageFileEditor, SIGNAL(currentIndexChanged(int)), - this, SLOT(enableButtons())); + connect(descriptionEditor, &QTextEdit::textChanged, [=]() { + enableButtons(); + }); + connect(imageFileEditor, QOverload::of(&QComboBox::currentIndexChanged), [=]() { + enableButtons(); + }); QFormLayout *formLayout = new QFormLayout; formLayout->addRow(itemLabel, itemText); @@ -109,7 +111,7 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *items, //! [4] //! [5] -int InformationWindow::id() +int InformationWindow::id() const { return itemId; } @@ -149,9 +151,9 @@ void InformationWindow::createButtons() closeButton->setDefault(true); - connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); - connect(revertButton, SIGNAL(clicked()), this, SLOT(revert())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submit())); + connect(closeButton, &QPushButton::clicked, this, &InformationWindow::close); + connect(revertButton, &QPushButton::clicked, this, &InformationWindow::revert); + connect(submitButton, &QPushButton::clicked, this, &InformationWindow::submit); //! [8] //! [9] diff --git a/examples/sql/drilldown/informationwindow.h b/examples/sql/drilldown/informationwindow.h index 6e87cea65a..653837d722 100644 --- a/examples/sql/drilldown/informationwindow.h +++ b/examples/sql/drilldown/informationwindow.h @@ -61,9 +61,9 @@ class InformationWindow : public QDialog public: InformationWindow(int id, QSqlRelationalTableModel *items, - QWidget *parent = 0); + QWidget *parent = nullptr); - int id(); + int id() const; signals: void imageChanged(int id, const QString &fileName); @@ -83,16 +83,16 @@ private: int itemId; QString displayedImage; - QComboBox *imageFileEditor; - QLabel *itemText; - QTextEdit *descriptionEditor; + QComboBox *imageFileEditor = nullptr; + QLabel *itemText = nullptr; + QTextEdit *descriptionEditor = nullptr; - QPushButton *closeButton; - QPushButton *submitButton; - QPushButton *revertButton; - QDialogButtonBox *buttonBox; + QPushButton *closeButton = nullptr; + QPushButton *submitButton = nullptr; + QPushButton *revertButton = nullptr; + QDialogButtonBox *buttonBox = nullptr; - QDataWidgetMapper *mapper; + QDataWidgetMapper *mapper = nullptr; }; //! [2] diff --git a/examples/sql/drilldown/main.cpp b/examples/sql/drilldown/main.cpp index 3465d11b4d..db3320de48 100644 --- a/examples/sql/drilldown/main.cpp +++ b/examples/sql/drilldown/main.cpp @@ -48,10 +48,13 @@ ** ****************************************************************************/ -#include - -#include "../connection.h" #include "view.h" +#include "../connection.h" + +#include + +#include + int main(int argc, char *argv[]) { @@ -60,7 +63,7 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); if (!createConnection()) - return 1; + return EXIT_FAILURE; View view("items", "images"); view.show(); diff --git a/examples/sql/drilldown/view.cpp b/examples/sql/drilldown/view.cpp index fc05d2fcaf..13e9310061 100644 --- a/examples/sql/drilldown/view.cpp +++ b/examples/sql/drilldown/view.cpp @@ -89,8 +89,6 @@ void View::addItems() int topMargin = 40; for (int i = 0; i < itemCount; i++) { - ImageItem *image; - QGraphicsTextItem *label; QSqlRecord record = itemTable->record(i); int id = record.value("id").toInt(); @@ -101,12 +99,12 @@ void View::addItems() int x = ((i % 2) * imageOffset) + leftMargin + columnOffset; int y = ((i / 2) * imageOffset) + topMargin; - image = new ImageItem(id, QPixmap(":/" + file)); + ImageItem *image = new ImageItem(id, QPixmap(":/" + file)); image->setData(0, i); image->setPos(x, y); scene->addItem(image); - label = scene->addText(item); + QGraphicsTextItem *label = scene->addText(item); label->setDefaultTextColor(QColor("#d7d6d5")); QPointF labelOffset((120 - label->boundingRect().width()) / 2, 120.0); label->setPos(QPointF(x, y) + labelOffset); @@ -133,22 +131,22 @@ void View::showInformation(ImageItem *image) return; InformationWindow *window = findWindow(id); - if (window && window->isVisible()) { - window->raise(); - window->activateWindow(); - } else if (window && !window->isVisible()) { - window->show(); - } else { - InformationWindow *window; + if (!window) { window = new InformationWindow(id, itemTable, this); - connect(window, SIGNAL(imageChanged(int,QString)), - this, SLOT(updateImage(int,QString))); + connect(window, QOverload::of(&InformationWindow::imageChanged), + this, QOverload::of(&View::updateImage)); window->move(pos() + QPoint(20, 40)); window->show(); informationWindows.append(window); } + + if (window->isVisible()) { + window->raise(); + window->activateWindow(); + } else + window->show(); } //! [6] @@ -172,19 +170,13 @@ void View::updateImage(int id, const QString &fileName) //! [7] //! [8] -InformationWindow* View::findWindow(int id) +InformationWindow *View::findWindow(int id) const { - QList::iterator i, beginning, end; - - beginning = informationWindows.begin(); - end = informationWindows.end(); - - for (i = beginning; i != end; ++i) { - InformationWindow *window = (*i); + for (auto window : informationWindows) { if (window && (window->id() == id)) return window; } - return 0; + return nullptr; } //! [8] diff --git a/examples/sql/drilldown/view.h b/examples/sql/drilldown/view.h index 9d6ef0e853..5afa1a25e9 100644 --- a/examples/sql/drilldown/view.h +++ b/examples/sql/drilldown/view.h @@ -63,7 +63,7 @@ class View : public QGraphicsView Q_OBJECT public: - View(const QString &items, const QString &images, QWidget *parent = 0); + View(const QString &items, const QString &images, QWidget *parent = nullptr); protected: void mouseReleaseEvent(QMouseEvent *event) override; @@ -77,7 +77,7 @@ private slots: //! [2] private: void addItems(); - InformationWindow* findWindow(int id); + InformationWindow *findWindow(int id) const; void showInformation(ImageItem *image); QGraphicsScene *scene; diff --git a/examples/sql/masterdetail/database.h b/examples/sql/masterdetail/database.h index 3139deb0b2..9cbca6f749 100644 --- a/examples/sql/masterdetail/database.h +++ b/examples/sql/masterdetail/database.h @@ -61,12 +61,12 @@ static bool createConnection() QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(":memory:"); if (!db.open()) { - QMessageBox::critical(0, qApp->tr("Cannot open database"), - qApp->tr("Unable to establish a database connection.\n" - "This example needs SQLite support. Please read " - "the Qt SQL driver documentation for information how " - "to build it.\n\n" - "Click Cancel to exit."), QMessageBox::Cancel); + QMessageBox::critical(nullptr, QObject::tr("Cannot open database"), + QObject::tr("Unable to establish a database connection.\n" + "This example needs SQLite support. Please read " + "the Qt SQL driver documentation for information how " + "to build it.\n\n" + "Click Cancel to exit."), QMessageBox::Cancel); return false; } diff --git a/examples/sql/masterdetail/dialog.cpp b/examples/sql/masterdetail/dialog.cpp index 5bb213230e..bb1812eace 100644 --- a/examples/sql/masterdetail/dialog.cpp +++ b/examples/sql/masterdetail/dialog.cpp @@ -155,12 +155,12 @@ int Dialog::addNewAlbum(const QString &title, int artistId) return id; } -void Dialog::addTracks(int albumId, QStringList tracks) +void Dialog::addTracks(int albumId, const QStringList &tracks) { QDomElement albumNode = albumDetails.createElement("album"); albumNode.setAttribute("id", albumId); - for (int i = 0; i < tracks.count(); i++) { + for (int i = 0; i < tracks.count(); ++i) { QString trackNumber = QString::number(i); if (i < 10) trackNumber.prepend('0'); @@ -254,9 +254,9 @@ QDialogButtonBox *Dialog::createButtons() closeButton->setDefault(true); - connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); - connect(revertButton, SIGNAL(clicked()), this, SLOT(revert())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submit())); + connect(closeButton, &QPushButton::clicked, this, &Dialog::close); + connect(revertButton, &QPushButton::clicked, this, &Dialog::revert); + connect(submitButton, &QPushButton::clicked, this, &Dialog::submit); QDialogButtonBox *buttonBox = new QDialogButtonBox; buttonBox->addButton(submitButton, QDialogButtonBox::ResetRole); @@ -270,7 +270,7 @@ QModelIndex Dialog::indexOfArtist(const QString &artist) { QSqlTableModel *artistModel = model->relationModel(2); - for (int i = 0; i < artistModel->rowCount(); i++) { + for (int i = 0; i < artistModel->rowCount(); ++i) { QSqlRecord record = artistModel->record(i); if (record.value("artist") == artist) return artistModel->index(i, 1); diff --git a/examples/sql/masterdetail/dialog.h b/examples/sql/masterdetail/dialog.h index 1789207d8d..31c4d8552c 100644 --- a/examples/sql/masterdetail/dialog.h +++ b/examples/sql/masterdetail/dialog.h @@ -61,7 +61,7 @@ class Dialog : public QDialog public: Dialog(QSqlRelationalTableModel *albums, QDomDocument details, - QFile *output, QWidget *parent = 0); + QFile *output, QWidget *parent = nullptr); private slots: void revert(); @@ -70,12 +70,12 @@ private slots: private: int addNewAlbum(const QString &title, int artistId); int addNewArtist(const QString &name); - void addTracks(int albumId, QStringList tracks); + void addTracks(int albumId, const QStringList &tracks); QDialogButtonBox *createButtons(); QGroupBox *createInputWidgets(); int findArtistId(const QString &artist); - int generateAlbumId(); - int generateArtistId(); + static int generateAlbumId(); + static int generateArtistId(); void increaseAlbumCount(QModelIndex artistIndex); QModelIndex indexOfArtist(const QString &artist); diff --git a/examples/sql/masterdetail/main.cpp b/examples/sql/masterdetail/main.cpp index cc1a1c4a21..9a4172e55f 100644 --- a/examples/sql/masterdetail/main.cpp +++ b/examples/sql/masterdetail/main.cpp @@ -48,11 +48,14 @@ ** ****************************************************************************/ -#include - #include "database.h" #include "mainwindow.h" +#include +#include + +#include + int main(int argc, char *argv[]) { Q_INIT_RESOURCE(masterdetail); @@ -60,10 +63,10 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); if (!createConnection()) - return 1; + return EXIT_FAILURE; - QFile *albumDetails = new QFile("albumdetails.xml"); - MainWindow window("artists", "albums", albumDetails); + QFile albumDetails("albumdetails.xml"); + MainWindow window("artists", "albums", &albumDetails); window.show(); return app.exec(); } diff --git a/examples/sql/masterdetail/mainwindow.cpp b/examples/sql/masterdetail/mainwindow.cpp index 9fbc4c43a4..7f3479619a 100644 --- a/examples/sql/masterdetail/mainwindow.cpp +++ b/examples/sql/masterdetail/mainwindow.cpp @@ -78,10 +78,10 @@ MainWindow::MainWindow(const QString &artistTable, const QString &albumTable, uniqueAlbumId = model->rowCount(); uniqueArtistId = artistView->count(); - connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), - this, SLOT(updateHeader(QModelIndex,int,int))); - connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), - this, SLOT(updateHeader(QModelIndex,int,int))); + connect(model, &QSqlRelationalTableModel::rowsInserted, + this, &MainWindow::updateHeader); + connect(model, &QSqlRelationalTableModel::rowsRemoved, + this, &MainWindow::updateHeader); QGridLayout *layout = new QGridLayout; layout->addWidget(artists, 0, 0); @@ -145,7 +145,7 @@ void MainWindow::showAlbumDetails(QModelIndex index) titleLabel->show(); QDomNodeList albums = albumData.elementsByTagName("album"); - for (int i = 0; i < albums.count(); i++) { + for (int i = 0; i < albums.count(); ++i) { QDomNode album = albums.item(i); if (album.toElement().attribute("id") == albumId) { getTrackList(album.toElement()); @@ -164,9 +164,9 @@ void MainWindow::getTrackList(QDomNode album) QDomNode track; QString trackNumber; - for (int j = 0; j < tracks.count(); j++) { + for (int i = 0; i < tracks.count(); ++i) { - track = tracks.item(j); + track = tracks.item(i); trackNumber = track.toElement().attribute("number"); QListWidgetItem *item = new QListWidgetItem(trackList); @@ -222,7 +222,7 @@ void MainWindow::removeAlbumFromFile(int id) QDomNodeList albums = albumData.elementsByTagName("album"); - for (int i = 0; i < albums.count(); i++) { + for (int i = 0; i < albums.count(); ++i) { QDomNode node = albums.item(i); if (node.toElement().attribute("id").toInt() == id) { albumData.elementsByTagName("archive").item(0).removeChild(node); @@ -283,8 +283,8 @@ QGroupBox* MainWindow::createArtistGroupBox() artistView->setModel(model->relationModel(2)); artistView->setModelColumn(1); - connect(artistView, SIGNAL(currentIndexChanged(int)), - this, SLOT(changeArtist(int))); + connect(artistView, QOverload::of(&QComboBox::currentIndexChanged), + this, &MainWindow::changeArtist); QGroupBox *box = new QGroupBox(tr("Artist")); @@ -314,10 +314,10 @@ QGroupBox* MainWindow::createAlbumGroupBox() locale.setNumberOptions(QLocale::OmitGroupSeparator); albumView->setLocale(locale); - connect(albumView, SIGNAL(clicked(QModelIndex)), - this, SLOT(showAlbumDetails(QModelIndex))); - connect(albumView, SIGNAL(activated(QModelIndex)), - this, SLOT(showAlbumDetails(QModelIndex))); + connect(albumView, &QTableView::clicked, + this, &MainWindow::showAlbumDetails); + connect(albumView, &QTableView::activated, + this, &MainWindow::showAlbumDetails); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(albumView, 0, 0); @@ -383,11 +383,16 @@ void MainWindow::createMenuBar() helpMenu->addAction(aboutAction); helpMenu->addAction(aboutQtAction); - connect(addAction, SIGNAL(triggered(bool)), this, SLOT(addAlbum())); - connect(deleteAction, SIGNAL(triggered(bool)), this, SLOT(deleteAlbum())); - connect(quitAction, SIGNAL(triggered(bool)), this, SLOT(close())); - connect(aboutAction, SIGNAL(triggered(bool)), this, SLOT(about())); - connect(aboutQtAction, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt())); + connect(addAction, &QAction::triggered, + this, &MainWindow::addAlbum); + connect(deleteAction, &QAction::triggered, + this, &MainWindow::deleteAlbum); + connect(quitAction, &QAction::triggered, + this, &MainWindow::close); + connect(aboutAction, &QAction::triggered, + this, &MainWindow::about); + connect(aboutQtAction, &QAction::triggered, + qApp, &QApplication::aboutQt); } void MainWindow::showImageLabel() diff --git a/examples/sql/masterdetail/mainwindow.h b/examples/sql/masterdetail/mainwindow.h index be3c6c94f4..dc6d8d1613 100644 --- a/examples/sql/masterdetail/mainwindow.h +++ b/examples/sql/masterdetail/mainwindow.h @@ -71,7 +71,7 @@ class MainWindow : public QMainWindow public: MainWindow(const QString &artistTable, const QString &albumTable, - QFile *albumDetails, QWidget *parent = 0); + QFile *albumDetails, QWidget *parent = nullptr); private slots: void about(); diff --git a/examples/sql/querymodel/customsqlmodel.h b/examples/sql/querymodel/customsqlmodel.h index 5d2f625665..462d2ab822 100644 --- a/examples/sql/querymodel/customsqlmodel.h +++ b/examples/sql/querymodel/customsqlmodel.h @@ -59,7 +59,7 @@ class CustomSqlModel : public QSqlQueryModel Q_OBJECT public: - CustomSqlModel(QObject *parent = 0); + CustomSqlModel(QObject *parent = nullptr); QVariant data(const QModelIndex &item, int role) const override; }; diff --git a/examples/sql/querymodel/editablesqlmodel.h b/examples/sql/querymodel/editablesqlmodel.h index 1341dd372a..e8caad2765 100644 --- a/examples/sql/querymodel/editablesqlmodel.h +++ b/examples/sql/querymodel/editablesqlmodel.h @@ -58,7 +58,7 @@ class EditableSqlModel : public QSqlQueryModel Q_OBJECT public: - EditableSqlModel(QObject *parent = 0); + EditableSqlModel(QObject *parent = nullptr); Qt::ItemFlags flags(const QModelIndex &index) const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; diff --git a/examples/sql/querymodel/main.cpp b/examples/sql/querymodel/main.cpp index 83804682f9..da19939dd8 100644 --- a/examples/sql/querymodel/main.cpp +++ b/examples/sql/querymodel/main.cpp @@ -48,12 +48,15 @@ ** ****************************************************************************/ -#include - #include "../connection.h" #include "customsqlmodel.h" #include "editablesqlmodel.h" +#include +#include + +#include + void initializeModel(QSqlQueryModel *model) { model->setQuery("select * from person"); @@ -80,7 +83,7 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); if (!createConnection()) - return 1; + return EXIT_FAILURE; QSqlQueryModel plainModel; EditableSqlModel editableModel; diff --git a/examples/sql/relationaltablemodel/relationaltablemodel.cpp b/examples/sql/relationaltablemodel/relationaltablemodel.cpp index 5292256cd9..c3c7d48d70 100644 --- a/examples/sql/relationaltablemodel/relationaltablemodel.cpp +++ b/examples/sql/relationaltablemodel/relationaltablemodel.cpp @@ -110,7 +110,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); if (!createConnection()) - return 1; + return EXIT_FAILURE; + createRelationalTables(); QSqlRelationalTableModel model; diff --git a/examples/sql/sqlbrowser/browser.cpp b/examples/sql/sqlbrowser/browser.cpp index d86c54404d..b05cf52099 100644 --- a/examples/sql/sqlbrowser/browser.cpp +++ b/examples/sql/sqlbrowser/browser.cpp @@ -165,11 +165,12 @@ void Browser::showTable(const QString &t) model->select(); if (model->lastError().type() != QSqlError::NoError) emit statusMessage(model->lastError().text()); + table->setModel(model); table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed); + connect(table->selectionModel(), &QItemSelectionModel::currentRowChanged, + this, &Browser::currentChanged); - connect(table->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), - this, SLOT(currentChanged())); updateActions(); } @@ -189,7 +190,6 @@ void Browser::showMetaData(const QString &t) model->setHeaderData(5, Qt::Horizontal, "AutoValue"); model->setHeaderData(6, Qt::Horizontal, "DefaultValue"); - for (int i = 0; i < rec.count(); ++i) { QSqlField fld = rec.field(i); model->setData(model->index(i, 0), fld.name()); diff --git a/examples/sql/sqlbrowser/browser.h b/examples/sql/sqlbrowser/browser.h index fef410778b..3f98f487c3 100644 --- a/examples/sql/sqlbrowser/browser.h +++ b/examples/sql/sqlbrowser/browser.h @@ -65,7 +65,7 @@ class Browser: public QWidget, private Ui::Browser { Q_OBJECT public: - Browser(QWidget *parent = 0); + Browser(QWidget *parent = nullptr); virtual ~Browser(); QSqlError addConnection(const QString &driver, const QString &dbName, const QString &host, @@ -116,7 +116,9 @@ class CustomModel: public QSqlTableModel { Q_OBJECT public: - explicit CustomModel(QObject *parent = 0, QSqlDatabase db = QSqlDatabase()):QSqlTableModel(parent, db) {} + explicit CustomModel(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase()) + : QSqlTableModel(parent, db) {} + QVariant data(const QModelIndex &idx, int role) const override { if (role == Qt::BackgroundRole && isDirty(idx)) diff --git a/examples/sql/sqlbrowser/connectionwidget.cpp b/examples/sql/sqlbrowser/connectionwidget.cpp index 888579c9af..658cfb77dc 100644 --- a/examples/sql/sqlbrowser/connectionwidget.cpp +++ b/examples/sql/sqlbrowser/connectionwidget.cpp @@ -63,8 +63,8 @@ ConnectionWidget::ConnectionWidget(QWidget *parent) tree->header()->setSectionResizeMode(QHeaderView::Stretch); QAction *refreshAction = new QAction(tr("Refresh"), tree); metaDataAction = new QAction(tr("Show Schema"), tree); - connect(refreshAction, SIGNAL(triggered()), SLOT(refresh())); - connect(metaDataAction, SIGNAL(triggered()), SLOT(showMetaData())); + connect(refreshAction, &QAction::triggered, this, &ConnectionWidget::refresh); + connect(metaDataAction, &QAction::triggered, this, &ConnectionWidget::showMetaData); tree->addAction(refreshAction); tree->addAction(metaDataAction); tree->setContextMenuPolicy(Qt::ActionsContextMenu); @@ -146,7 +146,6 @@ void ConnectionWidget::setActive(QTreeWidgetItem *item) void ConnectionWidget::on_tree_itemActivated(QTreeWidgetItem *item, int /* column */) { - if (!item) return; diff --git a/examples/sql/sqlbrowser/connectionwidget.h b/examples/sql/sqlbrowser/connectionwidget.h index 8b8e3a9a62..a805765f69 100644 --- a/examples/sql/sqlbrowser/connectionwidget.h +++ b/examples/sql/sqlbrowser/connectionwidget.h @@ -62,7 +62,7 @@ class ConnectionWidget: public QWidget { Q_OBJECT public: - ConnectionWidget(QWidget *parent = 0); + ConnectionWidget(QWidget *parent = nullptr); virtual ~ConnectionWidget(); QSqlDatabase currentDatabase() const; diff --git a/examples/sql/sqlbrowser/main.cpp b/examples/sql/sqlbrowser/main.cpp index 002dbc3242..ea4649b68d 100644 --- a/examples/sql/sqlbrowser/main.cpp +++ b/examples/sql/sqlbrowser/main.cpp @@ -80,16 +80,18 @@ int main(int argc, char *argv[]) mainWin.setCentralWidget(&browser); QMenu *fileMenu = mainWin.menuBar()->addMenu(QObject::tr("&File")); - fileMenu->addAction(QObject::tr("Add &Connection..."), &browser, SLOT(addConnection())); + fileMenu->addAction(QObject::tr("Add &Connection..."), + [&]() { browser.addConnection(); }); fileMenu->addSeparator(); - fileMenu->addAction(QObject::tr("&Quit"), &app, SLOT(quit())); + fileMenu->addAction(QObject::tr("&Quit"), []() { qApp->quit(); }); QMenu *helpMenu = mainWin.menuBar()->addMenu(QObject::tr("&Help")); - helpMenu->addAction(QObject::tr("About"), &browser, SLOT(about())); - helpMenu->addAction(QObject::tr("About Qt"), qApp, SLOT(aboutQt())); + helpMenu->addAction(QObject::tr("About"), [&]() { browser.about(); }); + helpMenu->addAction(QObject::tr("About Qt"), []() { qApp->aboutQt(); }); - QObject::connect(&browser, SIGNAL(statusMessage(QString)), - mainWin.statusBar(), SLOT(showMessage(QString))); + QObject::connect(&browser, &Browser::statusMessage, [&mainWin](const QString &text) { + mainWin.statusBar()->showMessage(text); + }); addConnectionsFromCommandline(app.arguments(), &browser); mainWin.show(); diff --git a/examples/sql/sqlbrowser/qsqlconnectiondialog.h b/examples/sql/sqlbrowser/qsqlconnectiondialog.h index d43955acdc..fc998d7ee9 100644 --- a/examples/sql/sqlbrowser/qsqlconnectiondialog.h +++ b/examples/sql/sqlbrowser/qsqlconnectiondialog.h @@ -60,7 +60,7 @@ class QSqlConnectionDialog: public QDialog { Q_OBJECT public: - QSqlConnectionDialog(QWidget *parent = 0); + QSqlConnectionDialog(QWidget *parent = nullptr); ~QSqlConnectionDialog(); QString driverName() const; diff --git a/examples/sql/sqlwidgetmapper/window.cpp b/examples/sql/sqlwidgetmapper/window.cpp index 21ce152169..b6946e2386 100644 --- a/examples/sql/sqlwidgetmapper/window.cpp +++ b/examples/sql/sqlwidgetmapper/window.cpp @@ -87,12 +87,12 @@ Window::Window(QWidget *parent) //! [Set up the mapper] //! [Set up connections and layouts] - connect(previousButton, SIGNAL(clicked()), - mapper, SLOT(toPrevious())); - connect(nextButton, SIGNAL(clicked()), - mapper, SLOT(toNext())); - connect(mapper, SIGNAL(currentIndexChanged(int)), - this, SLOT(updateButtons(int))); + connect(previousButton, &QPushButton::clicked, + mapper, &QDataWidgetMapper::toPrevious); + connect(nextButton, &QPushButton::clicked, + mapper, &QDataWidgetMapper::toNext); + connect(mapper, &QDataWidgetMapper::currentIndexChanged, + this, &Window::updateButtons); QGridLayout *layout = new QGridLayout(); layout->addWidget(nameLabel, 0, 0, 1, 1); diff --git a/examples/sql/sqlwidgetmapper/window.h b/examples/sql/sqlwidgetmapper/window.h index bff074d954..b336997360 100644 --- a/examples/sql/sqlwidgetmapper/window.h +++ b/examples/sql/sqlwidgetmapper/window.h @@ -72,7 +72,7 @@ class Window : public QWidget Q_OBJECT public: - Window(QWidget *parent = 0); + Window(QWidget *parent = nullptr); private slots: void updateButtons(int row); diff --git a/examples/sql/tablemodel/tablemodel.cpp b/examples/sql/tablemodel/tablemodel.cpp index c22e25cbef..a6e0341c23 100644 --- a/examples/sql/tablemodel/tablemodel.cpp +++ b/examples/sql/tablemodel/tablemodel.cpp @@ -47,12 +47,14 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - -#include -#include - #include "../connection.h" +#include +#include +#include + +#include + void initializeModel(QSqlTableModel *model) { model->setTable("person"); @@ -76,7 +78,7 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); if (!createConnection()) - return 1; + return EXIT_FAILURE; QSqlTableModel model;