QObject: Cannot create children for a parent that is in a different thread
2011-10-28 10:03
1516 查看
http://stackoverflow.com/questions/3268073/qobject-cannot-create-children-for-a-parent-that-is-in-a-different-thread
The run() member function is executed in a different thread, rather than the thread where QNetworkRequestManager object was created.
This kind of different-thread problems happen all the time with Qt when you use multiple threads. The canonical way to solve this problem is to use signals and slots.
Create a slot in the object where QNetworkRequestManager belongs to, create a signal in ResultThread and connect both of the somewhere, the constructor of ResultThread would be a good place.
The code which is currently in ResultThread::run() goes to the new slot, and is replaced by a emit(yourSignal()). If neccessary send a pointer to your ResultThread as a parameter with your emit function to gain access to member funtions/variables.
The run() member function is executed in a different thread, rather than the thread where QNetworkRequestManager object was created.
This kind of different-thread problems happen all the time with Qt when you use multiple threads. The canonical way to solve this problem is to use signals and slots.
Create a slot in the object where QNetworkRequestManager belongs to, create a signal in ResultThread and connect both of the somewhere, the constructor of ResultThread would be a good place.
The code which is currently in ResultThread::run() goes to the new slot, and is replaced by a emit(yourSignal()). If neccessary send a pointer to your ResultThread as a parameter with your emit function to gain access to member funtions/variables.
相关文章推荐
- qt#5 QObject: Cannot create children for a parent that is in a different thread.
- Qt出现QObject: Cannot create children for a parent that is in a different thread.问题
- 【Qt】Qt出现QObject: Cannot create children for a parent that is in a different thread.问题
- QObject: Cannot create children for a parent that is in a different thread.
- QObject: Cannot create children for a parent that is in a different thread.
- QObject: Cannot create children for a parent that is in a different thread
- Qt里出现 Cannot create children for a parent that is in a different thread
- Qt中次线程里创建对象,出现Cannot create children for a parent that is in a different thread
- QT线程出现错误Cannot create children for a parent that is in a different thread
- Cannot create children for a parent that is in a different thread
- Qt中次线程里创建对象,出现Cannot create children for a parent that is in a different thread
- QT出现 Cannot create children for a parent that is in a different thread 的解决方法:
- Qt Tcp多线程下QObject:Can not create children that is in different thread 的解决方法
- QThread报错: Cannot create children for a parent that is
- QThread报错: Cannot create children for a parent that is
- QThread报错: Cannot create children for a parent that is
- Remote Thread Execution in System Process using NtCreateThreadEx for Vista & Windows7
- 【转】[MySQL复制异常]Cannot execute statement: impossible to write to binary log since statement is in row for
- the name or security ID(SID) of the domain specified is inconsistent with the trust information for that domain
- The name or security ID (SID) of the domain specified is inconsistent with the trust information for that domain.