qthread

What happens to QThread when application is being closed without proper wait() call?

北城余情 提交于 2019-12-18 06:13:37
问题 In the example below (inside Qt GUI application) a new thread is started (with an event loop in which I want some work to be done): void doWork() { QThread* workerThread = new QThread(); Worker* worker = new Worker(); worker->moveToThread(workerThread); connect(workerThread, SIGNAL(started()), worker, SLOT(startWork())); connect(worker, SIGNAL(finished()), workerThread, SLOT(quit())); connect(workerThread, SIGNAL(finished()), worker, SLOT(deleteLater())); connect(workerThread, SIGNAL(finished

Why using QMetaObject::invokeMethod when executing method from thread

本秂侑毒 提交于 2019-12-18 04:41:49
问题 I have following code: class A : public QObject { Q_OBJECT public: A() : QObject() { moveToThread(&t); t.start(); } ~A() { t.quit(); t.wait(); } void doSomething() { QMetaObject::invokeMethod(this,"doSomethingSlot"); } public slots: void doSomethingSlot() { //do something emit ready(); } signals: void ready(); private: QThread t; } The question why from doSomething it must be call via QMetaObject::invokeMethod . I know that there is something with connection type. Could some one explain what

在Qt中程序休眠一段时间

自闭症网瘾萝莉.ら 提交于 2019-12-18 03:43:44
一:sleep,msleep,usleep 是QThread 下的三个静态函数 [static] void QThread::sleep(unsigned long secs) //秒 [static] void QThread::msleep(unsigned long msecs) //毫秒 [static] void QThread::usleep(unsigned long usecs) //微秒 使用方法: QThread::sleep(1);//休眠一秒 注意:不可在主线程中使用 二:利用 QElapsedTimer 来实现 QElapsedTimer类是提供了一种快速计算运行时间的方法 使用方法: QElapasedTimer m_elapasedTimer; m_elapasedTimer.start(); while(m_elapasedTimer.elapsed()<1000) { QCoreApplication::processEvents(); } 解释: q int64 QElapsedTimer::elapsed() const // 返回此QElapsedTimer最后一次启动后的毫秒数。 [static] void QCoreApplication::processEvents( QEventLoop::ProcessEventsFlags

QThreads , QObject and sleep function

六眼飞鱼酱① 提交于 2019-12-18 03:41:58
问题 The problem I encountered is that I decided to implement QThreads the way they are supposed to, based on numerous articles: http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/ http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/ and issue at hand is that since the algorithm is run in separate QObject (wrapped in QThread ) . how can I call out something like Thread::Sleep or smth .. Any ideas ? A small description of the software.

PySide/PyQt - Starting a CPU intensive thread hangs the whole application

百般思念 提交于 2019-12-17 23:35:15
问题 I'm trying to do a fairly common thing in my PySide GUI application: I want to delegate some CPU-Intensive task to a background thread so that my GUI stays responsive and could even display a progress indicator as the computation goes. Here is what I'm doing (I'm using PySide 1.1.1 on Python 2.7, Linux x86_64): import sys import time from PySide.QtGui import QMainWindow, QPushButton, QApplication, QWidget from PySide.QtCore import QThread, QObject, Signal, Slot class Worker(QObject): done

Why the QThread behave different if create it as local variable

我的未来我决定 提交于 2019-12-17 20:31:05
问题 I have found a strange behavior if I create QThread as local variable. For example, the following code will work as single thread, which means I need to wait 10 seconds and the result will come out. But if I change thread from local variable to member variable, it works as multi thread. How's it coming? Could anyone give me some tips? class UI(): def __init__(self): self.app = QtGui.QApplication(sys.argv) self.dialog = QtGui.QDialog() self.ui = Ui_Dialog() self.ui.setupUi(self.dialog) self.ui

Sending large amount of data between Qt threads

霸气de小男生 提交于 2019-12-17 17:34:26
问题 I have a QThread which generates a fairly large amount of data regularly (couple of megabytes per second), and it needs to transmit it to the parent (GUI) thread. I'm afraid I'm not that certain in the inner workings of QThread so I would like to ask for a best practice. Obviously, the most direct way to transmit data is to just emit an array. However, how efficient is this? Does Qt know about where it is used and avoids deep copying it when sending and receiving it? If not, I can gladly just

How to Compress Slot Calls When Using Queued Connection in Qt?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 10:42:47
问题 After reading some articles like this about Qt Signal-Slot communications I still have a question concerning the queued connection. If I have some threads sending signals all the time to each other and lets say one thread_slow is running a slow method in it's event loop and another thread_fast is running a fast one that sends multiple signals while the other thread is still running it's slow method.....when the slow method from thread_slow returns to the event loop, will it process all the

Qt signaling across threads, one is GUI thread?

瘦欲@ 提交于 2019-12-17 10:27:06
问题 What does it mean to move a object from one thread to another in Qt using moveToThread? Everything seems to work even before using moveToThread, which moves the object from one thread (GUI thread) to a another thread ( worked) and Qt:connect calls the appropriate slot on object. Is there any difference because of where the object lives, GUI thread or the worker thread? EDIT: I made a small program, but I don't understand how QThread works along with Signal and slot function, I would

Qt signals (QueuedConnection and DirectConnection)

我的梦境 提交于 2019-12-17 04:55:16
问题 I'm having trouble with Qt signals. I don't understand how DirectConnection and QueuedConnection works? I'd be thankful if someone will explain when to use which of these (sample code would be appreciated). 回答1: You won't see much of a difference unless you're working with objects having different thread affinities. Let's say you have QObjects A and B and they're both attached to different threads. A has a signal called somethingChanged() and B has a slot called handleChange() . If you use a