Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    1. Home
    2. Tags
    3. thread
    Log in to post

    • UNSOLVED It does not create a chart
      General and Desktop • qt5 thread chart • • suslucoder  

      14
      0
      Votes
      14
      Posts
      30
      Views

      @suslucoder What exactly can't you understand? In the documentation @SGaist posted there is even an example with signal/slot with parameter...
    • UNSOLVED error: type 'QObject' is not a direct base of 'MyThread'
      General and Desktop • qobject thread mainwindow • • suslucoder  

      11
      0
      Votes
      11
      Posts
      44
      Views

      @Christian-Ehrlicher thank you, i understand my mistake and solve it.
    • UNSOLVED PySide2 & Threading... how to set data on widget from thread?
      General and Desktop • pyside2 thread • • Dariusz  

      5
      0
      Votes
      5
      Posts
      153
      Views

      @eyllanesc said in PySide2 & Threading... how to set data on widget from thread?: @Dariusz said in PySide2 & Threading... how to set data on widget from thread?: Do not implement the same logic in the same class so "manager" should only process the data and send it, then connect that signal to the GUI so that it updates the information. Class Worker(QObject): sendData = Signal(str) def process(self): value = "foo" self.sendData.emit(value) class GUI(QWidget): def apply_data(self, text): self.foo.setText(text) worker = Worker() thread = QThread() worker.moveToThread(thread) gui = GUI() worker.sendData.connect(gui.apply_data) QTimer.singleShot(0, worker.process) By default in the connection AutoConnection is used so since the sender lives in the second thread and the receiver in the main thread then QueuedConnection will be used. Hmmm thank you, but will this work with python Thread ? As the worker thread, I got is not Qt...
    • UNSOLVED How to access the Accepted and Close Event of QDialogbox
      General and Desktop • c++ qdialog thread multithreading • • learnist  

      4
      0
      Votes
      4
      Posts
      65
      Views

      Hi, In your class declaration. Note that this is basic C++. If you do not know that, I highly encourage you to first improve your C++ knowledge before going further.
    • SOLVED Timer in worker object running on separate thread
      General and Desktop • qthread thread event loop exec • • chme  

      4
      0
      Votes
      4
      Posts
      96
      Views

      @jsulm: Thank you for your reply. The part I missed is "The default implementation simply calls exec()." @J.Hilk: Thank you for the great set of examples. IMHO, this should be placed in the QThread Class Documentation.
    • SOLVED Can you create slots in main.cpp file?
      General and Desktop • thread slots signals connection • • ples76  

      20
      0
      Votes
      20
      Posts
      336
      Views

      @ples76 said in Can you create slots in main.cpp file?: I have solved the problem with all of your help Great, so please don't forget to mark your post as solved! I am trying to find the easiest solution to this since I am under the gun to get this done asap Although you find a solution now, you may want to take into account that having such a main() function is not a good idea as @Christian-Ehrlicher pointed out. So time (and stakeholders) permitting, you might want to look at refactoring your code...
    • SOLVED GUI Freezes When Loop is Started
      QML and Qt Quick • qml thread function loop qml dynamic • • closx  

      7
      0
      Votes
      7
      Posts
      202
      Views

      @jsulm U are da king! I am dealing with QML for months, and just learning the property variables! That kinda saved my life mate! Thank you very much!
    • SOLVED messageBox not shown correctly
      General and Desktop • thread messagebox processevent • • dalishi  

      4
      0
      Votes
      4
      Posts
      247
      Views

      Hi guys I solved this problem by adding a sleeping time duration in my worker thread preventing it from returning too quick. Then the message box gets shown properly and closed properly. // member function to do the job bool MainWindow::waitReply() { // Here to sleep for a while QThread::sleep(2); bool received_valid_reply = false; while (!m_waitReplyCancelled) { if (Something Is Received) { received_valid_reply = true; return received_valid_reply; } } return received_valid_reply; }
    • Problem with SQLite Database and threads "Database is locked"
      General and Desktop • database thread • • davidesalvetti  

      14
      0
      Votes
      14
      Posts
      1435
      Views

      @davidesalvetti Hmm, I am not very confident in your solution. I would create a helper class to create/use right connection according to current thread. Something like this (it is just a skeleton, not sure it is working as it is): #include <QSqlDatabase> #include <QThread> class MyBDConnection { QString m_dbPath; QString m_dbName; Q_DISABLE_COPY(MyBDConnection) public: explicit MyBDConnection(const QString &sqlitePath, const QString &cnxName): m_dbPath(sqlitePath), m_dbName(cnxName) {} QSqlDatabase getDBConnection() { // Starting with Qt 5.11, sharing the same connection between threads is not allowed. // Use a dedicated connection for each thread requiring access to the database, // using the thread address as connection name. QSqlDatabase cnx; QString dbName = QStringLiteral("%1_%2").arg(m_dbName).arg(qintptr(QThread::currentThreadId()), 0, 16); if(QSqlDatabase::contains(dbName)) { cnx = QSqlDatabase::database(dbName); } else { cnx = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), dbName); cnx.setDatabaseName(m_dbPath); if (!cnx.isValid() || !cnx.open()) { qDebug() << "DB connection creation error!"; } } return cnx; } } And the only create on instance of this class and pass the pointer to each class which need connection to DB.
    • UNSOLVED Multi-thread GUI execution
      General and Desktop • gui thread multithreads executable • • sebs  

      7
      0
      Votes
      7
      Posts
      1020
      Views

      @sebs What I don't understand: you want an application with 3 threads, right? But why do you create new process?
    • UNSOLVED How to run a thread again?
      General and Desktop • thread threads threading ui object • • xLlama  

      4
      0
      Votes
      4
      Posts
      1484
      Views

      Hi, The terminate as it names suggest kills the the thread so it's state is not guaranteed as mentioned in the documentation. Not that you are automagically destroying everything once your operation is done. See your connections to the deleteLater slots.
    • UNSOLVED Terminate QThread correctly
      General and Desktop • thread qt4.8 yocto dizzy • • Andrea  

      11
      0
      Votes
      11
      Posts
      10261
      Views

      Hi @Andrea WOW! Infinite loop to just sleep and process events. Why not just start a timer of PreciseTimer and allow the events to flow freely in the thread? Since you want it to run as fast as possible you can even set the timeout to 0 to run freely when there are no events. You can then look at thread->requestInterruption () and the thread will comply! Just make sure if you are doing something in a loop in the timer callback you check thread ()->isInterruptionRequested (). And best of all... NO CHECKING THE EVENT QUEUE! There is a nice writeup about proper thread use at: https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/ You are basically there with your code. Just the loop is wasteful.
    • SOLVED Accessing the same Database from different threads
      General and Desktop • database sqlite thread • • davidesalvetti  

      3
      0
      Votes
      3
      Posts
      953
      Views

      @SGaist Thank you for your answer!
    • UNSOLVED Threading and Showing db tables with extra info
      General and Desktop • qtableview thread qsqlquerymodel qtablemodel • • Sanchezy  

      2
      0
      Votes
      2
      Posts
      603
      Views

      Hi and welcome to devnet, You can use a proxy model that adds the columns you want/need. You can keep updating the DB content and trigger the GUI update at some known interval or when a certains amount of changed happened to the database.
    • SOLVED Why QThread::wait() never returns after invoked QThread::quit()?
      General and Desktop • qthread thread quit deadlock wait • • Feuerteufel  

      8
      0
      Votes
      8
      Posts
      4363
      Views

      Ok, thanks, I think I have all information I need now.
    • UNSOLVED GL/D3D11 raw calls and swap/Present in standalone render thread
      General and Desktop • opengl thread rendering directx multithread • • JordanPKFX  

      1
      0
      Votes
      1
      Posts
      521
      Views

      No one has replied

    • UNSOLVED About Qt::DirectConnection
      General and Desktop • thread connect movetothread • • diverger  

      7
      0
      Votes
      7
      Posts
      4309
      Views

      @diverger As @micland already explained this does not have anything to do with Qt. It is a general problem with multi-threading: if you call a method from an object which leaves in another thread then you have to make sure this does not cause any problems.
    • UNSOLVED Return value from slot in differnet thread
      General and Desktop • thread slot return value • • McLion  

      12
      0
      Votes
      12
      Posts
      8123
      Views

      @VRonin Thanks for your input - there seem to be some misunderstanding. I can not and do not want to wait for the acknowledge of the server as a trigger to sent the next log message - this is against the idea. Log messages need always to be sent, regardless wether the server acknowledges or not - imagine the server even does not acknowledge. Every message sent has an ID# that is incremented by one for every new log message sent. The server acknowledges every message with returning the ID#. Looking at the network of the server with Wireshark and having incoming log messages with time stamps of the same msec - obviously the server has no time to send the acknowledge between incoming protocols. I.e. Sending #1 and # 2 in such a short sequence, obviously when sending #2 the counter for a missed message goes up to one. This is inherit by this system and is by design. Therefore, I'm going to implement a gap of at least a few msec between sending messages. Because the messages are all handled and forwarded in the application by signals / QtEvent queues, I dont have a solid idea so far how to do this. I may have to create a time gated sending queue before handing the messages over to the signal and the QtEvent queue.
    • SOLVED QDesktopWidget::.screenGeometry() from a Thread
      General and Desktop • thread geometry qscreen qdesktopwidget • • eKKiM  

      3
      0
      Votes
      3
      Posts
      1286
      Views

      Yes i did. And with that clue i figured it out! QApplication::desktop()->screenGeometry(screenIndex); works like a charm. Tyvm!
    • UNSOLVED readyRead of a socket in a seperate thread
      General and Desktop • thread socket readyread • • McLion  

      6
      0
      Votes
      6
      Posts
      2281
      Views

      @VRonin Server is on a different machine in the LAN and the software is not from me. I only implement the client side.
    • UNSOLVED Raspberry Pi thread - pure virtual function called
      Installation and Deployment • thread bug raspberry pi 2 g++ • • PeterPan32  

      5
      0
      Votes
      5
      Posts
      2552
      Views

      @SGaist said: mkspecs/device/linux-rasp-pi2-g++ Shouldn't it maybe be mkspecs/device/linux-rasp-pi-g++ (without the 2)? In his makefile there is this line: INCPATH = -I../threadtest -I. -I/usr/local/qt5/mkspecs/devices/linux-rasp-pi-g++
    • UNSOLVED Internal data exchange through threads with topic
      General and Desktop • qthread signal & slot thread • • lvjp  

      2
      0
      Votes
      2
      Posts
      787
      Views

      Hi, What about doing the subscription related stuff in your proxy ? Basically two methods: FeedProxy::subscribe(YouCoolClass *) FeedProxy::unsubscribe(YouCoolClass *) No need for any special detection and you know exactly where things are happening.
    • UNSOLVED Internal data exchange through threads with topic
      Brainstorm • qthread signal & slot thread • • lvjp  

      1
      0
      Votes
      1
      Posts
      477
      Views

      No one has replied

    • SOLVED Improving drawing/painting performance
      General and Desktop • thread draw paint • • SysTech  

      12
      0
      Votes
      12
      Posts
      6964
      Views

      @SysTech Thanks again! You're very welcome. Those 3D displays are kind of handy for visualizing the radio output but they are right now pretty CPU intensive. If I may insert yet another suggestion here. While I don't believe you'd gain much by using OpenGL painting for the "waterfall" data, I think switching to it for the 3D displays would work better. I nice side effect would be that you can also render OpenGL from different threads, provided the appropriate locking mechanisms are in place. You could, as the most simple test, try using QOpenGLWidget for those FFT displays. Kind regards.
    • UNSOLVED SqlModels: QSqlTableModel's that are created entirely from QML
      Showcase • qml sql model thread qsqltablemodel • • Leei  

      13
      0
      Votes
      13
      Posts
      3870
      Views

      @SGaist I don't mind refactoring it, it's not very long. I will definitely look into this. Thanks!
    • UNSOLVED Doc > Qt 4.8 > Mandelbrot Example
      General and Desktop • thread documentation syncronization docs • • dm_kiselev  

      10
      0
      Votes
      10
      Posts
      2382
      Views

      You're welcome ! Since it's all clear now, please mark the thread as solved using the "Topic Tool" button so that other forum users may know an answer has been found :)
    • QThread not exiting when signalled using SLOT(quit())
      General and Desktop • qthread thread signals & slots signals&slots qthreads • • zzaj  

      11
      0
      Votes
      11
      Posts
      4765
      Views

      @zzaj No problem. Good luck with your project!!
    • UNSOLVED QScriptEngine in a thread
      General and Desktop • thread qscriptengine • • SysTech  

      2
      0
      Votes
      2
      Posts
      1005
      Views

      Hi, I haven't used that class but from the looks of it, using the worker object approach should be fine.
    • UNSOLVED QObject::connect() vs thread
      General and Desktop • thread connect threading qt5.5.0 • • Pogi  

      4
      0
      Votes
      4
      Posts
      1553
      Views

      There's no multi-threading involved here whatsoever. All code here runs in a single thread (unless the timer object and "this" actually live in different threads). There's an event loop running in your app and timer events are just the same as any other. They get put in a queue and processed one after another. The above will basically mean that your slot is run every time Qt processes messages. It can have very bad influence on your app responsiveness if what you do in the slot is heavy. The most obvious question is: if you want a thread why not use an actual QThread instead of emulating it like that?
    • UNSOLVED Threads invoked for a simple application
      General and Desktop • qt5.5 thread • • vinothrajendran4  

      3
      0
      Votes
      3
      Posts
      781
      Views

      @SGaist : I am using Windows 7.....
    • SOLVED Question about Threads
      General and Desktop • thread • • RolBri  

      6
      0
      Votes
      6
      Posts
      1368
      Views

      Thank you all very much :-) I tested both and both works fine. The QMetaObject::invokeMethod is really convenient :-)
    • QMutex for Reading
      General and Desktop • thread mutex • • stvokr  

      2
      0
      Votes
      2
      Posts
      782
      Views

      @stvokr From experience: Your first assumption is incorrect: /* Thread not started, Mutex is not necessary */ What if someone calls startThread() after the thread is started (it is not correct, but can and possibly will happen)... So fist check m_run before going on to start the thread. Make the intention clear: Either make m_run atomic using either Qt atomics or C++11 atomics or protect it with mutexes wherever it is used. Then you do not need to worry about the way that it is implemented on the specific compiler. If it is really timing critical code then you can start to worry about the additional overhead. From a maintainability and readability point of view it is then easy to know that the variable in question can be accessed from other threads. From my understanding reading is mostly atomic, thus you do not need the locking for the read. Mark the variable as volatile. [edit] To answer the second question: Is it even necessary to use a mutex when a variable will only we written by one thread while other threads only read this variable? If you can guarantee that this will always be the way that it will be used then it should be ok. So if you are the only one developing on the code, and that will use the code perhaps you can. But if you share the code or need to re-use some parts down the line (in a few years perhaps) you might not remember that there is such a limitation. Rather safe than sorry. I hope this helps a bit, someone else might have better insights.
    • [SOLVED]Socket peer to peer communication for remote control
      General and Desktop • thread socket • • topix93  

      2
      0
      Votes
      2
      Posts
      1883
      Views

      SOLVED updating the client to Qt 5.5.0
    • [Solved] Serial - Thread - GUI - Webkit ... need suggestion
      Mobile and Embedded • gui thread webkit serial • • McLion  

      3
      0
      Votes
      3
      Posts
      1219
      Views

      I solved this. I moved everything related to the serial port into a separate class SerialWorker and moved it to a separate thread. QThread* serialthread = new QThread; SerialWorker* serialworker = new SerialWorker(); serialworker->moveToThread(serialthread); connect(serialthread, SIGNAL(started()), serialworker, SLOT(InitSerialPort())); serialthread->start(); connect(serialworker, SIGNAL(NewProto(QByteArray)), this, SLOT(ProtocolInterpreter(QByteArray))); connect(this, SIGNAL(SendRS(QByteArray)) , serialworker, SLOT(writeData(QByteArray))); This works as supposed. Serial port is now more or less very responsive. WebKit is still blocking the GUI thread sometimes but thats not as much an issue as the serial port not responding.
    • Calling functions on a QDialog from a different thread
      General and Desktop • qdialog thread • • Moschops  

      4
      0
      Votes
      4
      Posts
      2980
      Views

      Inter-thread communication is not an easy matter to be done properly. No you don't, check the worker object paradigm of QThread's documentation
    • [Solved] Running function with QtConcurrent::run
      Mobile and Embedded • thread function run concurrent • • McLion  

      9
      0
      Votes
      9
      Posts
      8479
      Views

      I'd like to add: Specially if the Watcher needs to be used multiple times it's important to disconnect it after use: disconnect(FormatWatcher, SIGNAL(finished()), this, SLOT(FinishedFormat())); // disconnect former slot used with watcher
    • What is the meaning of Thread affinity?
      General and Desktop • thread • • Hareen Laks  

      3
      0
      Votes
      3
      Posts
      2559
      Views

      @JKSH Thank you very much I think now I understood it. Thanks for the help.
    • [SOLVED] Debugger constantly stops in qglobal#qVersion()
      Tools • debug thread • • Henning Bredel  

      8
      0
      Votes
      8
      Posts
      2318
      Views

      @koahnig actually the project is using lots of locally compiled libs so a "quick" recompiling is not a possible solution to try out (qt uses different compiler with version newer than v5.2). However, once getting back to my problem I tested some debug config checkboxes and it turned out that the debug helpers were the "problem". Turning off showing thread names did not cause the debugger to stop deep in qt code several times anymore. In the end it is a pity not understanding what is going on when ticking that config option, though I am glad getting back to debugging now!
    • Problem with program that performs multiple processes.
      General and Desktop • python gui thread pyqt qtdesigner python3 threads threading pyqt4 multithreads pyuic • • Tas-sos  

      3
      0
      Votes
      3
      Posts
      2467
      Views

      How can i create my signal for text edit with python3 ? With as many ways i tried, but I did not succeed .. :(
    • How to FINALLY do asynchronous background worker with QThread
      General and Desktop • qthread thread threads asynchronous parallel • • Viktor Jamrich  

      12
      1
      Votes
      12
      Posts
      5348
      Views

      @JKSH Oh, did not catch that difference. Thank you.