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. wait for a db field set...
QtWS25 Last Chance

wait for a db field set...

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.2k 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.
  • Z Offline
    Z Offline
    zeroptr
    wrote on last edited by
    #1

    Hi all,

    at my application I need to wait for a db field gets a value... my code is like this.

    bool my_must_wait_func(int a_Var)
    {
    RECHECK:
    aQuery("select afield from aTable Where Afield = a_Var);
    
    if (!aQuery.value("afield").tobool ) {
          qApp->processEvents(QEventLoop::AllEvents);
          goto RECHECK;
    } else {
        return true;
    }
    
    }
    
    

    This func kills my database.. if I can query my db on every 250 ms it's enough for me..

    I couldnt manage it by timers.. they're going out of my func..

    Please Help...

    Linux Mint 20.04 64 Bit QT6.0.1

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

      Do you really have to wait "actively" in a function?
      You can use QTimer::singleShot() in the slot called after timeout you check the db value if it is not there you fire QTimer::singleShot() again. If the db field was changed you do what ever needs to be done and don't fire QTimer::singleShot() anymore.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zeroptr
        wrote on last edited by
        #3

        unfortunately yes...

        I have to be in that function...

        Linux Mint 20.04 64 Bit QT6.0.1

        mrjjM 1 Reply Last reply
        0
        • Z zeroptr

          unfortunately yes...

          I have to be in that function...

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

          @zeroptr
          Hi
          You can maybe use a lambda if u have c++ 11.

          void MyClass::SomeMethod(int a) {
          QTimer::singleShot(1000, { code..; } );
          }

          That will stay in same function sort of.

          Waiting in function in event driven applications like Qt is often just a bad idea. even when using qApp->processEvents.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zeroptr
            wrote on last edited by
            #5

            Hi @mrjj ,

            I don't think that single shot waits, until shot accures ?

            thanks for your help & idea..

            Linux Mint 20.04 64 Bit QT6.0.1

            mrjjM 1 Reply Last reply
            1
            • Z zeroptr

              Hi @mrjj ,

              I don't think that single shot waits, until shot accures ?

              thanks for your help & idea..

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

              @zeroptr
              hi
              After 1 sec (1000) it will call the "code" section.

              But why must u wait -IN- the function?

              Normal design would be using timer or thread to look in database over and over. and when seen value it would emit signal and the code
              that needs the value would run in the called slot.

              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