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. QTableWidget item signals executes only at the end of program execution

QTableWidget item signals executes only at the end of program execution

Scheduled Pinned Locked Moved Solved General and Desktop
qtablewidgetsignals & slotssignals emitthreadsteamspeak
7 Posts 3 Posters 270 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.
  • P Offline
    P Offline
    pruf
    wrote on 15 Feb 2025, 22:36 last edited by
    #1

    As the topic says, I have an item in table which has connected signal to main window function as presented here:

    connect(slider, &QSlider::valueChanged, this, &Widget::test);
    

    assuming it will execute every time i interact with it, but for whatever reason it yields down to program closure where these functions is not relevant anymore:

    -10-20-30-40-50-60-70-80-90pool dtor
    [max@arch tsproject]$ 
    

    (it also prints "pool dtor" every time program closes which is may be completely other issue)
    It have to be executed when it's expected to, as soon as the slider slided.
    Here's the Widget::test function:

    void Widget::test(int i)
    {
        printf("%i",i);
    }
    

    I've tried making table editable, using table->blockSignals(false);, using Lambda instead of slot-function, connecting table's itemChange instead of slider's valueChange. But anyway the signal executes only at the closure of application.
    I'm using TeamSpeak SDK which creates it's own thread to work with it's signals, and I'm emitting the function from one of these signals:

    static void hook_connection_status(uint64 serverConnectionHandlerID, int newStatus, uint errorNumber)
    {
        [...]
        anyID* list = new anyID[8] { 0 };
        ts3client_getClientList(serverConnectionHandlerID, &list);
        for (short int i=0; i < 8; i++)
        {
            if (list[i] != 0)
            {
                ts3client_getClientVariableAsString(serverConnectionHandlerID, list[i], CLIENT_NICKNAME, &client_nickname);
                QMetaObject::invokeMethod(w,"add_client", Qt::AutoConnection, Q_ARG(QString, QString(client_nickname)), Q_ARG(unsigned short, list[i]));
            }
        }
        [...]
    }
    

    I'm using "invokeMethod" to make sure the function executes inside of Qt thread or else there will be parenting issues and sliders appear as new windows.
    "add_client" is the function where that connection is made
    I'm using qtcreator but executing the program from inmade terminal emulator.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hskoglund
      wrote on 15 Feb 2025, 22:47 last edited by
      #2

      Maybe that thread needs a QEventloop instance and a call to it's exec function to properly send off those invokeMethods.

      P 1 Reply Last reply 16 Feb 2025, 12:46
      0
      • H hskoglund
        15 Feb 2025, 22:47

        Maybe that thread needs a QEventloop instance and a call to it's exec function to properly send off those invokeMethods.

        P Offline
        P Offline
        pruf
        wrote on 16 Feb 2025, 12:46 last edited by
        #3

        @hskoglund

        I tried initializing QEventLoop before "return application.exec()" in the end of main() function and replacing that line with return loop.exec(), also added loop->quit() in main window's closure event, nothing changed
        I tried appending while(true) loop before return which executes QEventLoop's processEvents() (then i've also tested the same for QCoreApplication::processEvents() and QApplication::processEvents()) but still no changes

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hskoglund
          wrote on 16 Feb 2025, 17:50 last edited by
          #4

          Perhaps its a QEventloop instance too much? If you do an exec() it will block the lower loop levels in the same thread until it call exit().
          You can check the loop level with something like
          qDebug() << QThread::currentThread()->loopLevel();

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 16 Feb 2025, 17:53 last edited by
            #5

            You don't need an extra event loop to process signals or slots in the main thread.
            Please provide a minimal, compilable example of your problem - what exactly are you doing and are you using threads in any way. Note that you must not access gui elements from outside the main thread.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            P 1 Reply Last reply 17 Feb 2025, 19:06
            1
            • C Christian Ehrlicher
              16 Feb 2025, 17:53

              You don't need an extra event loop to process signals or slots in the main thread.
              Please provide a minimal, compilable example of your problem - what exactly are you doing and are you using threads in any way. Note that you must not access gui elements from outside the main thread.

              P Offline
              P Offline
              pruf
              wrote on 17 Feb 2025, 19:06 last edited by
              #6

              guys.. I was just about to publish minimal example of this bug, when I just remembered that I haven't tried flushing stdout after every printf.. and guess what.. that really worked. I forgot about this 3 times when i was initially creating this topic. I've already tried it out in main app and it worked as well. so i guess topic closed.

              1 Reply Last reply
              1
              • P pruf has marked this topic as solved on 17 Feb 2025, 19:07
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 17 Feb 2025, 19:50 last edited by
                #7

                That's the reason we request a mre 🙂

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1

                7/7

                17 Feb 2025, 19:50

                • Login

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