Re: [Interest] Using QWebSocketServer in a thread other than the GUI thread?
2015-05-27 9:43 GMT+02:00 Rainer Wiesenfarth rainer_wiesenfa...@trimble.com : (Qt 5.3.2 Windows msvc-2010 64bit) I would like to add a QWebSocketServer to an existing application. I would like to have all its operation handled by a thread different from the GUI thread to get communication separated from the GUI part. However, when I use moveToThread with the QWebServerSocket, I get these warnings on incoming connections: QObject: Cannot create children for a parent that is in a different thread. (Parent is QNativeSocketEngine(0x1b12ab0), parent's thread is QThread( GUI_thread ), current thread is QThread( communication_thread ) In addition, the disconnect event never comes through, probably as a consequence of the warning. Question: Is it possible to use QWebSocketServer in a thread other than the GUI thread? How? I think the real question is why you would want to do that. Unless you're handling an insane amount of traffic, the communication is not going to be a bottle neck that affects GUI interaction in a negative way. I think you better keep your QWebSocketServer in your main thread. If you need to do CPU intensive processing of the messages, I think it is better you off-load the actual processing to separate threads. Elvis Best Regards / Mit freundlichen Grüßen Rainer Wiesenfarth -- Software Engineer | Trimble Imaging Division Rotebühlstraße 81 | 70178 Stuttgart | Germany Office +49 711 22881 0 | Fax +49 711 22881 11 http://www.trimble.com/imaging/ | http://www.inpho.de/ Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim Eingetragen beim Amtsgericht Darmstadt unter HRB 83893, Geschäftsführer: Dr. Frank Heimberg, Hans-Jürgen Gebauer ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Using QWebSocketServer in a thread other than the GUI thread?
Am 27.05.2015 um 11:48 schrieb Elvis Stansvik: 2015-05-27 Rainer Wiesenfarth: Question: Is it possible to use QWebSocketServer in a thread other than the GUI thread? How? I think the real question is why you would want to do that. [...] In my special case: to create a communication service component for use inside an application that may or may not have a running event loop. Thus the component thread's event loop should do the necessary handling. Best Regards / Mit freundlichen Grüßen Rainer Wiesenfarth -- Software Engineer | Trimble Imaging Division Rotebühlstraße 81 | 70178 Stuttgart | Germany Office +49 711 22881 0 | Fax +49 711 22881 11 http://www.trimble.com/imaging/ | http://www.inpho.de/ Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim Eingetragen beim Amtsgericht Darmstadt unter HRB 83893, Geschäftsführer: Dr. Frank Heimberg, Hans-Jürgen Gebauer smime.p7s Description: S/MIME Cryptographic Signature ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Using QWebSocketServer in a thread other than the GUI thread?
Before making the moveToThread(), remove the parent of the object, -setParent(nullptr); Once moved, you can reparent with object into that Thread. Note, if using QItem there's also the QQmlEngine that own the item that is tie to a thread. On Wed, May 27, 2015 at 3:43 AM, Rainer Wiesenfarth rainer_wiesenfa...@trimble.com wrote: (Qt 5.3.2 Windows msvc-2010 64bit) I would like to add a QWebSocketServer to an existing application. I would like to have all its operation handled by a thread different from the GUI thread to get communication separated from the GUI part. However, when I use moveToThread with the QWebServerSocket, I get these warnings on incoming connections: QObject: Cannot create children for a parent that is in a different thread. (Parent is QNativeSocketEngine(0x1b12ab0), parent's thread is QThread( GUI_thread ), current thread is QThread( communication_thread ) In addition, the disconnect event never comes through, probably as a consequence of the warning. Question: Is it possible to use QWebSocketServer in a thread other than the GUI thread? How? Best Regards / Mit freundlichen Grüßen Rainer Wiesenfarth -- Software Engineer | Trimble Imaging Division Rotebühlstraße 81 | 70178 Stuttgart | Germany Office +49 711 22881 0 | Fax +49 711 22881 11 http://www.trimble.com/imaging/ | http://www.inpho.de/ Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim Eingetragen beim Amtsgericht Darmstadt unter HRB 83893, Geschäftsführer: Dr. Frank Heimberg, Hans-Jürgen Gebauer ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Using QWebSocketServer in a thread other than the GUI thread?
Am 27.05.2015 um 15:49 schrieb Jérôme Godbout: Before making the moveToThread(), remove the parent of the object, -setParent(nullptr); Once moved, you can reparent with object into that Thread. The QWebSocketServer does not have a parent. The problem does not occur with this class itself, but with QNativeSocketEngine, which seems to exist somewhere in the depth of Qt. The QNativeSocketEngine was created by Qt internals in the GUI thread context, but is now used by the QWebSocketServer which lives in a separate thread. Seems these two classes do not expect this to happen... [...] On Wed, May 27, 2015 at 3:43 AM, Rainer Wiesenfarth rainer_wiesenfa...@trimble.com mailto:rainer_wiesenfa...@trimble.com wrote: (Qt 5.3.2 Windows msvc-2010 64bit) I would like to add a QWebSocketServer to an existing application. I would like to have all its operation handled by a thread different from the GUI thread to get communication separated from the GUI part. However, when I use moveToThread with the QWebServerSocket, I get these warnings on incoming connections: QObject: Cannot create children for a parent that is in a different thread. (Parent is QNativeSocketEngine(0x1b12ab0), parent's thread is QThread( GUI_thread ), current thread is QThread( communication_thread ) In addition, the disconnect event never comes through, probably as a consequence of the warning. Question: Is it possible to use QWebSocketServer in a thread other than the GUI thread? How? [...] Best Regards / Mit freundlichen Grüßen Rainer Wiesenfarth -- Software Engineer | Trimble Imaging Division Rotebühlstraße 81 | 70178 Stuttgart | Germany Office +49 711 22881 0 | Fax +49 711 22881 11 http://www.trimble.com/imaging/ | http://www.inpho.de/ Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim Eingetragen beim Amtsgericht Darmstadt unter HRB 83893, Geschäftsführer: Dr. Frank Heimberg, Hans-Jürgen Gebauer smime.p7s Description: S/MIME Cryptographic Signature ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Using QWebSocketServer in a thread other than the GUI thread?
On Wednesday 27 May 2015 10:53:06 Jérôme Godbout wrote: removing parent is essential http://doc.qt.io/qt-5/qobject.html#moveToThread The object cannot be moved if it has a parent. The children will follow to the new thread. For the reparenting, maybe you can shed some light on it. From what I understand, moveToThread, make that thread responsible to delete the object and own him now (the object have the thread affinity to that thread from now on), why can't you use a parent into that thread then? You can use a parent that lives in that thread. The problem is that you suggested parenting back to the thread object, which doesn't have affinity to the thread it started. On Wednesday 27 May 2015 09:49:06 Jérôme Godbout wrote: Before making the moveToThread(), remove the parent of the object, -setParent(nullptr); Once moved, you can reparent with object into that Thread. No, you cannot. The parent must be another object that lives in the current thread. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Using QWebSocketServer in a thread other than the GUI thread?
Rainer wrote: I would like to add a QWebSocketServer to an existing application. I would like to have all its operation handled by a thread different from the GUI thread to get communication separated from the GUI part. If you create the QWebSocketServer in the thread's run override, does that fix your issue with QNativeSocketEngine? Regards, Tony ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Using QWebSocketServer in a thread other than the GUI thread?
On Wednesday 27 May 2015 17:34:11 Rainer Wiesenfarth wrote: The QWebSocketServer does not have a parent. The problem does not occur with this class itself, but with QNativeSocketEngine, which seems to exist somewhere in the depth of Qt. The QNativeSocketEngine was created by Qt internals in the GUI thread context, but is now used by the QWebSocketServer which lives in a separate thread. Seems these two classes do not expect this to happen... Report a bug. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Using QWebSocketServer in a thread other than the GUI thread?
removing parent is essential http://doc.qt.io/qt-5/qobject.html#moveToThread The object cannot be moved if it has a parent. The children will follow to the new thread. For the reparenting, maybe you can shed some light on it. From what I understand, moveToThread, make that thread responsible to delete the object and own him now (the object have the thread affinity to that thread from now on), why can't you use a parent into that thread then? Thread#1: - ObjA - ObjB as child of A Thread#2: - ObjC Code: ObjB-setParent(nullptr); ObjB-moveToThread(Thread2); Now you have: Thread#1: - ObjA Thread#2: - ObjC - ObjB why inside thread2 set parent of ObjB to ObjC is bad? to get the following: Thread#2: - ObjC - ObjB as child of C On Wed, May 27, 2015 at 10:23 AM, Thiago Macieira thiago.macie...@intel.com wrote: On Wednesday 27 May 2015 09:49:06 Jérôme Godbout wrote: Before making the moveToThread(), remove the parent of the object, -setParent(nullptr); Once moved, you can reparent with object into that Thread. No, you cannot. The parent must be another object that lives in the current thread. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
[Interest] Using QWebSocketServer in a thread other than the GUI thread?
(Qt 5.3.2 Windows msvc-2010 64bit) I would like to add a QWebSocketServer to an existing application. I would like to have all its operation handled by a thread different from the GUI thread to get communication separated from the GUI part. However, when I use moveToThread with the QWebServerSocket, I get these warnings on incoming connections: QObject: Cannot create children for a parent that is in a different thread. (Parent is QNativeSocketEngine(0x1b12ab0), parent's thread is QThread( GUI_thread ), current thread is QThread( communication_thread ) In addition, the disconnect event never comes through, probably as a consequence of the warning. Question: Is it possible to use QWebSocketServer in a thread other than the GUI thread? How? Best Regards / Mit freundlichen Grüßen Rainer Wiesenfarth -- Software Engineer | Trimble Imaging Division Rotebühlstraße 81 | 70178 Stuttgart | Germany Office +49 711 22881 0 | Fax +49 711 22881 11 http://www.trimble.com/imaging/ | http://www.inpho.de/ Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim Eingetragen beim Amtsgericht Darmstadt unter HRB 83893, Geschäftsführer: Dr. Frank Heimberg, Hans-Jürgen Gebauer smime.p7s Description: S/MIME Cryptographic Signature ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest