Text box is not refreshing content on window.
-
int main(int argc, char *argv[]) { uint32_t discovered = 0; QApplication a(argc, argv); MainWindow w; w.show(); QObject::connect(&m_sys, &SYS::SendMessage, &w, &MainWindow::DisplayTerminalMessage); QObject::connect(&m_comparser, &COMPARSER::SendMessage, &w, &MainWindow::DisplayTerminalMessage); QObject::connect(&m_commands, &COMMANDS::SendMessage, &w, &MainWindow::DisplayTerminalMessage); QObject::connect(&m_sensor, &SENSOR::SendMessage, &w, &MainWindow::DisplayTerminalMessage); QObject::connect(&m_script, &SCRIPT::SendMessage, &w, &MainWindow::DisplayTerminalMessage); //load parameters+script from a default file location m_sys.ParamInit(nullptr); m_sys.ScriptInit(sys_params.script_file); rt_params.connected = wifi_udp.Start(sys_params.local_ip, sys_params.local_port); if (rt_params.connected ) m_sys.Print("UDP - OK\n"); else m_sys.Print("UDP - FAIL\n"); w.repaint(); //does not help w.update(); //does not help discovered = m_sensor.DiscoverConcurrent(0, 4, SYS_DISC_MODE_ALL); QFuture<void> future = QtConcurrent::run(&ScriptRun); return a.exec(); }
The function m_sensor.DiscoverConcurrent - runs concurrent - a separated thread and should not block the GUI thread.
If I comment m_sensor.DiscoverConcurrent - all functions (m_sys.ParamInit, m_sys.ScriptInit) print some messages in a text box and I see it and it's OK.
But if m_sensor.DiscoverConcurrent runs - it blocks the text box and I don't see any prints (it captures a part of the desktop). After m_sensor.DiscoverConcurrent finishes - all prints available in the text box.
It doesn't affect functionality but looks ugly to a user. -
@jenya7 said in Text box is not refreshing on window.:
But if m_sensor.DiscoverConcurrent runs - it blocks the text box and I don't see any prints
Sounds like m_sensor.DiscoverConcurrent is a blocking call and does NOT run concurrently.
-
@jsulm said in Text box is not refreshing on window.:
@jenya7 said in Text box is not refreshing on window.:
But if m_sensor.DiscoverConcurrent runs - it blocks the text box and I don't see any prints
Sounds like m_sensor.DiscoverConcurrent is a blocking call and does NOT run concurrently.
May be.
uint32_t SENSOR::DiscoverConcurrent(uint8_t min, uint8_t max, uint8_t mode) { QFuture<uint32_t> future; rt_params.service = 1; switch (mode) { case SYS_DISC_MODE_ALL: future = QtConcurrent::run(this, &SENSOR::DiscoverByIndexAll, max); break; case SYS_DISC_MODE_RANGE: future = QtConcurrent::run(this, &SENSOR::DiscoverByIndexRange, min, max); break; case SYS_DISC_MODE_FILE: future = QtConcurrent::run(this, &SENSOR::DiscoverByList); break; } rt_params.service = 0; return future; }
At least I try. I get no exceptions or run time messages. How can I be sure another thread was created?
The function is executed - I see result on finish. -
@jenya7
I assumeuint32_t SENSOR::DiscoverConcurrent(uint8_t min, uint8_t max, uint8_t mode) { QFuture<uint32_t> future; .... return future; }
does an implicit call to result() to return the uint32_t value,
which will wait until the concurrent has run its course.
Congratulations, you turned it back into a synchronous program :P
give the QFuture object to an QFutureWatcher instance and listen to the finished signal there.
-
@J-Hilk said in Text box is not refreshing content on window.:
does an implicit call to result() to return the uint32_t value
Yes, this is also what I think is happeneing, but can't find anything related to this in QFuture documentation.
-
@jsulm probably this one ?
-
@jenya7 said in Text box is not refreshing content on window.:
I fixed it
I bet you did not, because discovered variable is still uint32_t, right?
Please read what @J-Hilk wrote. -
@jsulm said in Text box is not refreshing content on window.:
@jenya7 said in Text box is not refreshing content on window.:
I fixed it
I bet you did not, because discovered variable is still uint32_t, right?
Please read what @J-Hilk wrote.Now it is
in main.cppQFuture<uint32_t> discovered;
in sensor.cpp
QFuture<uint32_t> SENSOR::DiscoverConcurrent()........
Still the same.
Wait a minute... SENSOR::DiscoverConcurrent calls
future = QtConcurrent::run(this, &SENSOR::DiscoverByIndexAll, max);
so SENSOR::DiscoverByIndexAll - should be also QFuture<uint32_t> ?
well..the problem is only on start up. If I call SENSOR::DiscoverConcurrent() from another place (after return a.exec();) it works good.
-
@jenya7 said in Text box is not refreshing content on window.:
What event to connect?
Why do you need an event/signal for that?
Just call it after a.exec()... -
@jsulm said in Text box is not refreshing content on window.:
@jenya7 said in Text box is not refreshing content on window.:
What event to connect?
Why do you need an event/signal for that?
Just call it after a.exec()...what is "after"?
int main(int argc, char *argv[]) { ............ return a.exec(); discovered = m_sensor.DiscoverConcurrent(0, 4, SYS_DISC_MODE_ALL); }
code will never be executed.
-
@jenya7 said in Text box is not refreshing content on window.:
code will never be executed
Well, it is really not hard to change this code in a way it does what you want.
But I will let this simple exercise to you...