Solved Problem connecting database notification
I am building a database app. It is mostly working well, but I would like for my QTableView to be updated when the database is updated. I'm trying to use notifications to do this. This works but I get the error message
QMetaObject::connectSlotsByName: No matching signal for on_database_notification(QString)
even though a qDebug() line in on_database_notification(QString) prints, showing that it gets called.
To connect the notification signal to my handler I'm using the following line:
QObject::connect(_pgDB.driver(), SIGNAL(notification(const QString&)), this, SLOT(on_database_notification(const QString&)));
What is the proper syntax for connecting this signal to this slot? I would prefer to use the modern syntax for this, but the docs on this aren't very clear to me.
You're likely using a designer base widget. If so slots name starting with
on_are used to automatically create connections between widgets defined with designer and code you wrote in your widget class. The most simple thing to do is to rename it e.g.
Why can't you use the new syntax ?
Thank you @SGaist . Renaming the handler did indeed get rid of the error message.
I'm now using
QObject::connect(_pgDB.driver(),static_cast<void(QSqlDriver::*)(const QString &)>(&QSqlDriver::notification),this,&MainWindow::onDatabaseNotification);
and all is well. I can't really say that I understand the cast though. Obviously it's indicating which of the overloaded notification methods I'm wanting, but I'm having a hard time wrapping my head around it.
You understood it correctly.
Note that since 5.7 you can use qOverload which makes the code easier to read.