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. QSqlDriver notification
Forum Updated to NodeBB v4.3 + New Features

QSqlDriver notification

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 3.1k Views 2 Watching
  • 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.
  • Y Offline
    Y Offline
    Yacinoben
    wrote on last edited by
    #1

    Hello,
    I would like to use a notifications of QSqlDriver when a value in the table (Count) has changed.

    I use Postgre.

    code source :

       if(!query.exec("Notify Count"))
                       qDebug()<<query->lastError().text();
    
       if(!m_db.driver()->subscribeToNotification("Count"))
         {
           qDebug()<<m_db.driver()->lastError().text();
           m_db.close();
           qApp->quit();
         }
      connect(m_db.driver(), static_cast<void(QSqlDriver::*)(const QString &)>(&QSqlDriver::notification), [](const QString &name){qDebug("notification"); });
    

    When the table is updated by another program, i don't receive a notification.

    source code of the other program :

     if(!query.exec("UPDATE Count SET  Counter = Counter+1"))
                 qDebug()<<)query.lastError().text();
    

    Thank's

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      But you do get a notification if same program changes the db ?

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        Yacinoben
        wrote on last edited by
        #3

        No, i haven't a notification

        mrjjM 1 Reply Last reply
        0
        • Y Yacinoben

          No, i haven't a notification

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Yacinoben

          Did you check with HasFeature if it can do it ?
          http://doc.qt.io/qt-5/qsqldriver.html#hasFeature

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            Yacinoben
            wrote on last edited by
            #5
              qDebug()<<m_db.driver()->hasFeature(QSqlDriver::EventNotifications);
            

            return true.

            mrjjM 1 Reply Last reply
            0
            • Y Yacinoben
                qDebug()<<m_db.driver()->hasFeature(QSqlDriver::EventNotifications);
              

              return true.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Super. it should work.
              I dont have PostG. DB so can't play with it

              Does the queries all work ?

              Syntax looks odd to me but I guess its valid

              https://www.postgresql.org/docs/9.0/static/sql-notify.html

              Sorry, not sure how to test this further.

              1 Reply Last reply
              1
              • Y Offline
                Y Offline
                Yacinoben
                wrote on last edited by
                #7

                All query works, I don't know what to do

                mrjjM 1 Reply Last reply
                0
                • Y Yacinoben

                  All query works, I don't know what to do

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Yacinoben
                  Hi
                  I would find some other tool to test if notification does indeed work.
                  So i know it must be something in my program or Qt.

                  https://jdbc.postgresql.org/documentation/91/listennotify.html

                  1 Reply Last reply
                  1
                  • Y Offline
                    Y Offline
                    Yacinoben
                    wrote on last edited by
                    #9

                    up ?
                    I have tried everything, but nothing.

                    1 Reply Last reply
                    0
                    • Y Offline
                      Y Offline
                      Yacinoben
                      wrote on last edited by Yacinoben
                      #10

                      it's solved. In postgre i wrote "CREATE RULE name AS ON UPDATE TO nameTable DO NOTIFY notification_name

                      https://www.postgresql.org/docs/8.1/static/rules-update.html

                      1 Reply Last reply
                      2

                      • Login

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