Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem connecting database notification
QtWS25 Last Chance

Problem connecting database notification

Scheduled Pinned Locked Moved Solved General and Desktop
signals&slotssqlnotification
4 Posts 2 Posters 1.7k Views
  • 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 Offline
    M Offline
    mjsurette
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      1
      • M Offline
        M Offline
        mjsurette
        wrote on last edited by
        #3

        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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved