Results 1 to 20 of 20

Thread: Sample for Mutithreading

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Sample for Mutithreading

    I tried adding these = 0 but it did not change anything

    Qt Code:
    1. #ifndef SERIALHANDLERBASE_H
    2. #define SERIALHANDLERBASE_H
    3.  
    4. #include <QObject>
    5.  
    6. class SerialHandlerBase : public QObject
    7. {
    8. Q_OBJECT
    9. public:
    10. SerialHandlerBase();
    11. virtual void startHandling() = 0;
    12. virtual void stopHandling() = 0;
    13. };
    14.  
    15. #endif // SERIALHANDLERBASE_H
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Sample for Mutithreading

    Did you run qmake after adding the Q_OBJECT macro to your class?
    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.


  3. #3
    Join Date
    Jun 2010
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Sample for Mutithreading

    Quote Originally Posted by wysota View Post
    Did you run qmake after adding the Q_OBJECT macro to your class?
    This was the reason. Perfect thanks :-)

    I'll try to implement the handler class now. Am I able to set the owner thread to sleep ? I think my next question will be concerning connecting the signals of the objects of the serial thread to the slots of the object in the database thread.

    But berfore asking this I'll do some trials on my own.

    Thank you very much for your patience.

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

    Default Re: Sample for Mutithreading

    Again, you only need one thread. Not one for serial, one for database, one for something else. One in general, it's not java.
    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.


  5. #5
    Join Date
    Jun 2010
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Sample for Mutithreading

    Quote Originally Posted by wysota View Post
    Again, you only need one thread. Not one for serial, one for database, one for something else. One in general, it's not java.
    Hmm.. I seem to be too focused to my standard development environment in c# and java. I'll try to sort it out in my mind. My fear is that the task that occur sometime will interrupt the data retrieval process. From time to time the saved data needs to be sent as xml to a web page. The data needs to be displayed in the gui and so on.

    I think I'll need the one or other day to get into the "best practices" for QT.

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

    Default Re: Sample for Mutithreading

    Nothing will interrupt anything and you won't have problems with synchronizing all the threads. Just start thinking in asynchronous manner.
    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.


  7. #7
    Join Date
    May 2008
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Asynchronous handling vs multiple threads

    Quote Originally Posted by wysota View Post
    Nothing will interrupt anything and you won't have problems with synchronizing all the threads. Just start thinking in asynchronous manner.
    @wysota:

    this is interesting as i'm also looking into implementing threaded architecture. from what you are suggesting single thread with asynchronous handling will do the job. but isn't it much more efficient if multiple threads are involved? let's take for an example a method(slot) handling the signal in a single thread, wouldn't that stop or delay other processing as compared to concurrent processing in multithreads?
    i'm still quite undecided whether to implement asynchronous handling in one thread or implement multiple threads. would really appreciate your expert advice as to which one is more efficient. thanks.

  8. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Asynchronous handling vs multiple threads

    It seems that your threads will be mostly I/O bound - ie, they will spend most of there time waiting for an i/o event to complete, so really, it makes no sense to use them for these functions (you can of course, but it'll just use up more resources and make coding more difficult).

    If you were doing something like a long computation then threads would indeed make sense, but your serial routines definitely do not need threads, and your database thread is questionable too (ie, you would have to be doing some heavy processing over millions of rows and not just simple inserts or selects)

  9. The following user says thank you to squidge for this useful post:

    jimc1200 (1st July 2010)

  10. #9
    Join Date
    May 2008
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Asynchronous handling vs multiple threads

    Quote Originally Posted by fatjuicymole View Post
    It seems that your threads will be mostly I/O bound - ie, they will spend most of there time waiting for an i/o event to complete, so really, it makes no sense to use them for these functions (you can of course, but it'll just use up more resources and make coding more difficult).

    If you were doing something like a long computation then threads would indeed make sense, but your serial routines definitely do not need threads, and your database thread is questionable too (ie, you would have to be doing some heavy processing over millions of rows and not just simple inserts or selects)

    Thanks fatjuicymole for your insights. I think a single thread with asynchronous handling will satisfy my requirements for now.I'll try to check if there's any considerable slow down in the IO operations and if such is the case I might start adding threads. But that would be my last resort as threading adds significant complications in the code ,more so when debugging

Similar Threads

  1. UTF-8 Issues in Sample
    By trevelyan in forum Newbie
    Replies: 6
    Last Post: 19th May 2011, 01:41
  2. Problem with QSettings sample
    By neoclaw in forum Qt Programming
    Replies: 3
    Last Post: 3rd June 2010, 09:52
  3. Question regarding the flicklist qt sample
    By advokate3 in forum Qt Programming
    Replies: 0
    Last Post: 8th December 2009, 20:15
  4. mysql connection sample
    By mohanakrishnan in forum Newbie
    Replies: 3
    Last Post: 12th November 2009, 16:23
  5. Trouble building a sample (4.6)
    By Asperamanca in forum Newbie
    Replies: 12
    Last Post: 21st October 2009, 08:55

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
  •  
Qt is a trademark of The Qt Company.