Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved Problem connecting database notification

    General and Desktop
    signals&slots sql notification
    2
    4
    1241
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mjsurette last edited by

      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.

      Thank you.

      Mike

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        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. onDatabaseNotifcations.

        Why can't you use the new syntax ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 1
        • M
          mjsurette last edited by

          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.

          Thanks again

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            You understood it correctly.

            Note that since 5.7 you can use qOverload which makes the code easier to read.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post