QTableWidget item signals executes only at the end of program execution
-
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. -
I tried initializing QEventLoop before "return application.exec()" in the end of
main()
function and replacing that line withreturn loop.exec()
, also addedloop->quit()
in main window's closure event, nothing changed
I tried appendingwhile(true)
loop beforereturn
which executes QEventLoop'sprocessEvents()
(then i've also tested the same forQCoreApplication::processEvents()
andQApplication::processEvents()
) but still no changes -
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. -
guys.. I was just about to publish minimal example of this bug, when I just remembered that I haven't tried flushing
stdout
after everyprintf
.. 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. -
-
That's the reason we request a mre 🙂