Page 2 of 2 FirstFirst 12
Results 21 to 38 of 38

Thread: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Quote Originally Posted by prof.ebral View Post
    Hmmm, I thought the main thread received the signal as a handler and then executed the method defined by the slot.
    No, it depends on the thread affinity of the object that the slot belongs to. Here is a simple example:

    Qt Code:
    1. #include <QtCore>
    2.  
    3. class Object : public QObject {
    4. Q_OBJECT
    5. public:
    6. Object(QObject *parent = 0) : QObject(parent) {
    7.  
    8. }
    9. public slots:
    10. void reportThread() {
    11. qDebug() << Q_FUNC_INFO << QThread::currentThread();
    12. }
    13. };
    14.  
    15. #include "main.moc"
    16.  
    17. int main(int argc, char **argv) {
    18. QCoreApplication app(argc, argv);
    19.  
    20. QVector<QThread*> threads;
    21. QVector<Object*> objects;
    22. for(int i=0;i<4;++i) {
    23. QThread *thr = new QThread;
    24. threads << thr;
    25.  
    26. Object *o = new Object;
    27. o->moveToThread(thr);
    28. objects << o;
    29.  
    30. thr->start();
    31.  
    32. }
    33. // last object in main thread
    34. objects << new Object;
    35. qDebug() << "GUI thread:" << objects.last()->thread();
    36. QTimer t;
    37. t.start(2000);
    38. foreach(Object *o, objects)
    39. QObject::connect(&t, SIGNAL(timeout()), o, SLOT(reportThread()));
    40. return app.exec();
    41. }
    To copy to clipboard, switch view to plain text mode 

    You can also move the timer to one of the threads and see if it changes anything.

    Oh, one more thing -- you can run this example under a debugger, set a breakpoint in the slot and look at the backtrace. You'll see how it differs for the last added object (the one that lives in the main thread) compared to other objects.
    Last edited by wysota; 11th December 2012 at 22:20.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #22
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Ok, thanks wysota. I use PyQt and when I look at the current thread inside a method that has been called by a signal it is the main thread. I've yet to see an instance when it is isn't in PyQt.

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Quote Originally Posted by prof.ebral View Post
    Ok, thanks wysota. I use PyQt and when I look at the current thread inside a method that has been called by a signal it is the main thread. I've yet to see an instance when it is isn't in PyQt.
    Maybe you are using Python threads and not QThreads. I have no idea how Qt will behave then.

    I ran this test program:

    python Code:
    1. from PySide import QtCore
    2. import sys
    3.  
    4. class Object(QtCore.QObject):
    5. def reportThread(self):
    6. print(QtCore.QThread.currentThread())
    7.  
    8. app = QtCore.QCoreApplication(sys.argv)
    9. thr = QtCore.QThread()
    10. obj = Object()
    11.  
    12. timer = QtCore.QTimer()
    13. print("MainThread"+str(QtCore.QThread.currentThread()))
    14. timer.timeout.connect(obj.reportThread)
    15. timer.start(2000)
    16. app.exec_()
    To copy to clipboard, switch view to plain text mode 

    and it behaves the same way as I described:

    MainThread<PySide.QtCore.QThread object at 0xf6a050>
    <PySide.QtCore.QThread object at 0xf6a0e0>
    <PySide.QtCore.QThread object at 0xf6a0e0>
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #24
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    This is the output I get
    Qt Code:
    1. MainThread<PyQt4.QtCore.QThread object at 0x7f16ef83c408>
    2. <PyQt4.QtCore.QThread object at 0x7f16ef83c408>
    To copy to clipboard, switch view to plain text mode 
    The main thread is located at the same memory allocation as all of the other threads.

    edit: By the way, here is the changed code for PyQt
    Qt Code:
    1. from PyQt4 import QtCore
    2. import sys
    3.  
    4. class Object(QtCore.QObject):
    5. def reportThread(self):
    6. print(QtCore.QThread.currentThread())
    7.  
    8. app = QtCore.QCoreApplication(sys.argv)
    9. thr = QtCore.QThread()
    10. obj = Object()
    11.  
    12. timer = QtCore.QTimer()
    13. print("MainThread"+str(QtCore.QThread.currentThread()))
    14. timer.timeout.connect(obj.reportThread)
    15. timer.start(2000)
    16. app.exec_()
    To copy to clipboard, switch view to plain text mode 
    Not much different.

  5. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Maybe that's an issue with PyQt4 (I would rather suspect that it returns an incorrect thread pointer rather than runs the slot in a wrong thread). As you can see I was using PySide.


    Edit: LOL... I forgot to move the object to the thread and start the thread

    Here is a working version:

    python Code:
    1. from PyQt4 import QtCore
    2. import sys
    3.  
    4. class Object(QtCore.QObject):
    5. def __init__(self):
    6. QtCore.QThread.__init__(self)
    7.  
    8. def reportThread(self):
    9. print(QtCore.QThread.currentThreadId())
    10.  
    11. app = QtCore.QCoreApplication(sys.argv)
    12. thr = QtCore.QThread()
    13. obj = Object()
    14. obj.moveToThread(thr)
    15. thr.start()
    16.  
    17. timer = QtCore.QTimer()
    18. print("MainThread"+str(QtCore.QThread.currentThreadId()))
    19. timer.timeout.connect(obj.reportThread)
    20. timer.start(2000)
    21.  
    22. t2 = QtCore.QTimer()
    23. t2.timeout.connect(app.quit)
    24. t2.start(10000)
    25. app.exec_()
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 11th December 2012 at 23:16.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #26
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Quote Originally Posted by wysota View Post
    Maybe that's an issue with PyQt4 (I would rather suspect that it returns an incorrect thread pointer rather than runs the slot in a wrong thread). As you can see I was using PySide.
    I think it is a feature of PyQt. I'll have to check over the documentation again, but I think PyQt signals and slots operate 'through' the main thread. Like how I described before. Sorry for adding confusion to the post.

  7. #27
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    No, it's not a feature of PyQt. Look at my previous post, I just edited it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #28
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    That doesn't work for me. I only receive the MainThread print statement in my terminal.

    edit: wysota, here is some modified code and the output. Even after the Object class is moved to the Thread class I still get the main thread's ID ... but for me the signal is not being caught by the Object's reportThread method.

    Qt Code:
    1. from PyQt4 import QtCore
    2. import sys, time
    3.  
    4. class Object(QtCore.QObject):
    5. def __init__(self):
    6. QtCore.QObject.__init__(self)
    7.  
    8. def reportThread(self):
    9. print self, (QtCore.QThread.currentThreadId())
    10.  
    11. class Thread(QtCore.QThread):
    12. def __init__(self):
    13. QtCore.QThread.__init__(self)
    14.  
    15. def reportThread(self):
    16. print self, (QtCore.QThread.currentThreadId())
    17.  
    18. app = QtCore.QCoreApplication(sys.argv)
    19. thr = Thread()
    20. obj = Object()
    21. obj.moveToThread(thr)
    22. print obj, obj.thread(), obj.thread().currentThreadId()
    23. thr.start()
    24.  
    25. timer = QtCore.QTimer()
    26. print ( "MainThread "+str(QtCore.QThread.currentThreadId()) )
    27. timer.timeout.connect(obj.reportThread)
    28. timer.timeout.connect(thr.reportThread)
    29. timer.start(2000)
    30.  
    31. t2 = QtCore.QTimer()
    32. t2.timeout.connect(app.quit)
    33. t2.start(10000)
    34. app.exec_()
    To copy to clipboard, switch view to plain text mode 

    output:
    Qt Code:
    1. <__main__.Object object at 0xabd2f8> <__main__.Thread object at 0xabd270> 140273089054464 MainThread 140273089054464
    2. <__main__.Thread object at 0xabd270> 140273089054464
    3. <__main__.Thread object at 0xabd270> 140273089054464
    4. <__main__.Thread object at 0xabd270> 140273089054464
    5. <__main__.Thread object at 0xabd270> 140273089054464
    6. <__main__.Thread object at 0xabd270> 140273089054464
    To copy to clipboard, switch view to plain text mode 
    Last edited by prof.ebral; 11th December 2012 at 23:54.

  9. #29
    Join Date
    Nov 2008
    Posts
    183
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    I don't know who is "everyone" and what they "suggested", I'm not telling you to look at examples but to use QIODevice API like it is supposed to be used. You can search the Internet for similar discussions on doing networking with threads. "Everyone" "suggests" this is supposed to be done in threads because that's how they have been doing it using other technologies that didn't provide non-blocking API. It is not supposed to be done in threads.
    Yes it is. Please do not try to view this application in terms of something running on a machine where the user can also surf the Web and check email.


    Which is exactly my point. You don't need "non-blocking threads" (whatever you mean by that) to handle serial ports simply because the operating system will buffer data for you. If you are running 115200 baud transmission, it doesn't mean you need to read 115200 bits per second. It means you need to read 115200 per second on average. This is only 14kB per port, I'm sure single thread can handle reading 16 of these per second and still be able to do some fancy stuff in your UI.
    That is very poor design and not allowed in a scientific environment were loss of a single data point scraps the entire test run.

    Did it come to your mind to do this "minutes if not hours" lasting processing in a thread (or even in a separate process)? Are you really blocking your UI for "minutes if not hours" and still think that's ok? Are you sure it is me who never did any data aquisition and processing?

    Oh jeez, and you want to process it in the GUI thread? That's so professional...
    It is a design requirement. Do not confuse this with some application on a machine which has any other purpose or ability in life. The really large data sets can and do get off-loaded to serious computers for detailed analysis. The initial analysis to weed out non-interesting data sets occurs on the collection machine. What you consider a waste saves weeks and in some cases months of serious computing time.

    You have to be kidding. If you are worried about it and are unable to check if that is really the case then do proper synchronization in your code.

    Stop trolling and claiming to have all the answers and start reading on proper usage of components at hand. Your post on disabled copy constructor in a QObject subclass clearly shows how well you understand Qt code.
    I'm not trolling or claiming to have all of the answers. I came in asking if there was unit test code proving this works. I got a bunch of responses which sounded like a Bing commercial.

    My next debugging course was to use the signal tool, but any class which does not have a copy constructor cannot be used with it...a point you have repeatedly failed to recognize.

    Please don't view this as a user application. This is a single purpose system running in an environment were no data point can be lost. Every device must be service by a non-blocking thread and those threads must be distributed across processors. It is not an end user application nor a hokey little smart phone app. It gathers all data points and the GUI only has two purposes. 1) Configure everything for a test run 2) run the reports/graphs used to identify interesting data sets. That's it.



    Some of them might even not be emitted at all
    Hence the wish to test with the signal tool.



    Are you talking about your own projects or projects in general?
    Projects which get released for use with Qt. I find they only provide unit test code/examples for GUI use, and nothing for use within non-GUI threads.

    At any rate. This message thread can now end. I'm on my own fixing it or I have to switch to qextserial.


    Added after 7 minutes:


    As far as I understand data sent by signals is sent to the main thread. You are asking for this, "Looking actual compiling example of SerialPort class using signals and slots within a thread which is NOT the GUI thread."
    http://doc.qt.digia.com/qt/threads-q...across-threads

    Queued Connection The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed in the receiver's thread.
    Last edited by RolandHughes; 12th December 2012 at 14:59.

  10. #30
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Quote Originally Posted by prof.ebral View Post
    That doesn't work for me. I only receive the MainThread print statement in my terminal.

    edit: wysota, here is some modified code and the output. Even after the Object class is moved to the Thread class I still get the main thread's ID ...
    That's because the Thread object lives in the main thread. You only moved the Object instance to the thread, not the Thread instance. There is a distinction between a thread (as in a separate processing flow) and QThread instance.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #31
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Quote Originally Posted by wysota View Post
    That's because the Thread object lives in the main thread. You only moved the Object instance to the thread, not the Thread instance. There is a distinction between a thread (as in a separate processing flow) and QThread instance.
    >____< I used the code you gave me. "I" did not do that. Anyway, thank you.

  12. #32
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Quote Originally Posted by RolandHughes View Post
    Yes it is. Please do not try to view this application in terms of something running on a machine where the user can also surf the Web and check email.
    And how is that related to anything we've been discussing about? I don't care where the application runs. I care that a single thread doesn't have any problems in reading data from multiple sockets/ports.

    That is very poor design and not allowed in a scientific environment were loss of a single data point scraps the entire test run.
    What is poor design and how does having another thread prevent loss of some data that would otherwise magically be lost? Data is not lost if you read it 10ms later or 20ms later or even 2 seconds later. It's still there. What matters is that you read data fast enough to prevent cluttering the input buffer. And even that is nothing wrong if you are using TCP as the protocol itself is designed to prevent any data loss. Your serial port doesn't have that safety mechanism and thus you need to pay attention to read the data fast enough to not overrun the input buffer for the port. But it totally doesn't matter which thread performs the read.

    It is a design requirement. Do not confuse this with some application on a machine which has any other purpose or ability in life.
    Strange. Somehow your flaws are "by design" (yeah yeah, it's a feature, not a bug) and something you consider a "flaw" in others' thinking is "unserious school project". Be serious. Any unresponsive system is badly designed. Period.

    I'm not trolling or claiming to have all of the answers. I came in asking if there was unit test code proving this works. I got a bunch of responses which sounded like a Bing commercial.
    Yes, you are trolling. Just read your posts.

    a point you have repeatedly failed to recognize.
    So... QPushButton is also badly designed because it also has a disabled copy constructor? What about QSignalSpy itself? It also has a disabled copy constructor. So does every QObject-derived class. And so does QtSerialPort which is a sign of good design on behalf of its author.

    Please don't view this as a user application. This is a single purpose system running in an environment were no data point can be lost.
    I'm sorry but as a user of any user application I would not like to have any of my data lost too. And as a programmer of such applications I wouldn't want to have any data lost. Your system is by no means special.

    Hence the wish to test with the signal tool.
    If you test with the signal tool, the signal will be emitted because the connection from the tool will make its emitter emit it. I think you fail to understand what I meant. Read the docs for QObject::receivers() to see what I meant and how does QSignalSpy influence it.

    Projects which get released for use with Qt.
    No. My projects never loose any signals, they don't loose any "data points" nor anything like that. They often use multithreading and classes from them are often thread-safe. So please talk about your projects, not about others'.

    This message thread can now end.
    Thank you, your Grace, for giving us your permission

    Quote Originally Posted by prof.ebral View Post
    >____< I used the code you gave me. "I" did not do that. Anyway, thank you.
    You subclassed QThread. I didn't.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #33
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Quote Originally Posted by wysota View Post
    You subclassed QThread. I didn't.
    I used the original code, then modified the code to show the thread Id. The original code did not work for me. I posted that. This conversation between you and me is of no value, and you seem to have a problem reading.

  14. #34
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Look, the essential difference between code from posts #25 (mine) and #28 (yours) is that the code in post #28 subclasses QThread and connects to a slot from an instance of this class (lines 11-16 and 28). This is why you get the id of the main thread --- because QThread instance lives in the main thread. If you always do that in your code (meaning you connect a signal to a slot in the QThread subclass) then indeed all slots are executed in the context of the main thread, because that's where the QThread subclass instance lives. The modification you did in post #28 to my code from post #25 is what makes the difference between your output and mine.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #35
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Wysota ... the Object doesn't even execute the reportThread method in your code, nor in mine. I'm trying to point that out to you. Like I said, you have a hard time reading.

    Here ... I will quote my post:
    "That doesn't work for me. I only receive the MainThread print statement in my terminal.

    edit: wysota, here is some modified code and the output. Even after the Object class is moved to the Thread class I still get the main thread's ID ... but for me the signal is not being caught by the Object's reportThread method."

  16. #36
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Quote Originally Posted by prof.ebral View Post
    Wysota ... the Object doesn't even execute the reportThread method in your code, nor in mine. I'm trying to point that out to you. Like I said, you have a hard time reading.
    I understand that it doesn't work for you, I don't know why. It works for me just fine and I'm sure it works for many other people because it is intended to work that way.

    Even after the Object class is moved to the Thread class I still get the main thread's ID ... but for me the signal is not being caught by the Object's reportThread method."
    You get the main thread ID's because you connect the timer's signal to the slot of an object that lives in main thread.

    I just tried running the code you posted but it bails out with a syntax error (I'm using Python 3):

    text Code:
    1. File "./code.py", line 11
    2. print self, (QtCore.QThread.currentThreadId())
    3. ^
    To copy to clipboard, switch view to plain text mode 

    After fixing those syntax errors (by putting print arguments in parenthesis) and running the code, I get this:

    <__main__.Object object at 0x7fa7c3b50b00> <__main__.Thread object at 0x7fa7c3b50a70> 140358524008192
    MainThread 140358524008192
    <__main__.Thread object at 0x7fa7c3b50a70> 140358524008192
    <__main__.Object object at 0x7fa7c3b50b00> 140358466680576
    <__main__.Thread object at 0x7fa7c3b50a70> 140358524008192
    <__main__.Object object at 0x7fa7c3b50b00> 140358466680576

    You can see two slots are called -- one in Object (with thread id 576) and the other one in Thread (with thread id 192). That's the correct behaviour as described in Qt docs (PyQt can't possibly work differently because it's just a wrapper over Qt C++ classes). I don't know why you're getting no output for Object, the most obvious reason is that the worker thread is not started (or its event loop is not running).

    A side note: I checked with Python2.7 and it works the same way as with Python3:
    (<__main__.Object object at 0x7fa08aaf7d40>, <__main__.Thread object at 0x7fa08aaf7cb0>, 140327479097088L)
    MainThread 140327479097088
    (<__main__.Thread object at 0x7fa08aaf7cb0>, 140327479097088L(<__main__.Object object at 0x7fa08aaf7d40>, 140327422002944L)
    )
    (<__main__.Thread object at 0x7fa08aaf7cb0>, 140327479097088L)
    (<__main__.Object object at 0x7fa08aaf7d40>, 140327422002944L)
    (<__main__.Thread object at 0x7fa08aaf7cb0>, 140327479097088L)
    (<__main__.Object object at 0x7fa08aaf7d40>, 140327422002944L)
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #37
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Quote Originally Posted by wysota View Post
    You can see two slots are called -- one in Object (with thread id 576) and the other one in Thread (with thread id 192). That's the correct behaviour as described in Qt docs (PyQt can't possibly work differently because it's just a wrapper over Qt C++ classes). I don't know why you're getting no output for Object, the most obvious reason is that the worker thread is not started (or its event loop is not running).
    That is why I subclassed it. The thread starts. You can modify the run or start methods and determine that if you want. I don't know why either.

  18. #38
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need Qt SerialPort class example using signals and slots WITHIN A THREAD

    Quote Originally Posted by prof.ebral View Post
    The thread starts.
    How do you know that? There is no code in your program that verifies if the thread is running.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Signals Slots and Class Pointers
    By Atomic_Sheep in forum Newbie
    Replies: 18
    Last Post: 7th September 2012, 10:08
  2. [Signals & Slots] Custom class' signal not detected
    By Mr_Cloud in forum Qt Programming
    Replies: 5
    Last Post: 26th July 2012, 11:35
  3. Thread safety with signals and slots
    By blooglet in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2012, 16:03
  4. Are signals and slots thread safe?
    By Cruz in forum Qt Programming
    Replies: 12
    Last Post: 21st April 2011, 15:57
  5. Access a class without using Signals/Slots
    By impeteperry in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2010, 12:14

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.