Results 1 to 4 of 4

Thread: Qthread Issue?

  1. #1
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Qthread Issue?

    Hi All,

    I m working on Qt 4.2.2 on my Intel Mac.

    I m new to QThread.

    I have a simple QThread program in which I have a call

    class MyThread : public QThread
    {
    public:
    void run();
    };

    and I m reimplementing the run as ..

    void MyThread::run()
    {

    Form1 *myForm;
    myForm->CallThread();
    }

    which is calling the CallThread function of the form1 class in which I m starting my Thread.

    MyThread fileThread;

    fileThread.start();
    fileThread.wait();

    If I donot use the wait the Thread will not start.
    But now then thread is started and call the function

    void Form1::CallThread()
    {

    QMessageBox::information(0,"Stellar Phoenix","I m in Thread calling Function");


    }

    and show the Message .
    But my Question are

    The Program is Get hanged after showing the Message and also give error in log that We can not use font and text outside the Gui Thread.

    I have used flag to terminate the thread but its not working for me.

    If anybody knows then plz help me.

    Thanks.

  2. #2
    Join Date
    Aug 2006
    Location
    Switzerland
    Posts
    52
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qthread Issue?

    Quote Originally Posted by vishal.chauhan View Post
    Hi All,
    Hi, first of all use [code] tags
    Quote Originally Posted by vishal.chauhan View Post
    Qt Code:
    1. class MyThread : public QThread
    2. {
    3. public:
    4. void run();
    5. }
    6.  
    7. void MyThread::run()
    8. {
    9. Form1 *myForm;
    10. myForm->CallThread();
    11. }
    12.  
    13. void Form1::CallThread()
    14. {
    15. QMessageBox::information(0,"Stellar Phoenix","I m in Thread calling Function");
    16. }
    To copy to clipboard, switch view to plain text mode 

    The Program is Get hanged after showing the Message and also give error in log that We can not use font and text outside the Gui Thread.
    You are not allowed to use Gui classes (like QMessageBox) in your own threads. But you can for example emit a signal from your thread which is connected with a slot working in Gui (main) thread which will display a message box.
    The Wheel weaves as the Wheel wills.

  3. #3
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Re: Qthread Issue?

    Thanks for Reply.

    But I donot know How can Pass Signal to the Main Thread and Recieve that signal in Main Thread?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qthread Issue?

    Read Thread Support in Qt - Signals and Slots Across Threads and take a look at the examples mentioned.
    J-P Nurmi

Similar Threads

  1. QGraphicsScene and QThread
    By tts80 in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2007, 09:32
  2. QThread call-once semantics?
    By brcain in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2006, 21:25
  3. Replies: 5
    Last Post: 22nd September 2006, 08:04
  4. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 11:19
  5. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 22:51

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.