Results 1 to 5 of 5

Thread: error in creating QThread and Pthread

  1. #1
    Join Date
    Jul 2011
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation error in creating QThread and Pthread

    hi, i like to implement client and server model in qt. i ve done that, and now am gonna use multiple client. so am following threads.. i ve learned qthreads and used but got run time error . couldn’t found that.. here’s the code. in header file i declared.like
    QT Code:

    class mythread:public QThreads,public Widget
    {
    public:
    void run();
    }
    and .cpp file i defined it as,

    QT Code:

    void mythread::run()
    {
    //my client code
    exec();
    }

    mythread t;
    t.start();
    t.wait();

    but i got sum error like debugger crashed and sometime program is not running. kindly tell me what i need to change here in the code. as am new to qt, kindly help me as soon as possible.

    becos of error in QThread i plan to use pthread. as i ve already experience in linux so implemented pthread but it shows some syntax error couldn’t found tat too..

    QT Code:

    void *mythread(void*);
    pthread_create(&threadid;,0,(void*)&mythread;,0);


    but it shows invalid argument 3 in pthread. the same way i ve used it in linux, there works, here its not working.. kindly tell me how to use the pthread(tell me the syntax properly) and modify here to use…and also tell if i ve used pthread it may create any problem while executing. like in gcc i ve used -lpthread in run time like tat i need to add any library or it will work by default.. if we want to add any library kindly give me full explanation about pthread to use it in qt

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: error in creating QThread and Pthread

    You don't have to use threads to service multiple clients but you can if you wish. The documentation contains two examples of exactly the sort of thing you are wanting to do:
    Fortune Server Example
    Threaded Fortune Server

    Ultimately, if you plan to use pthreads then there is no point in us fixing your Qt code and the pthreads question should be addressed to another forum.

  3. #3
    Join Date
    Jul 2011
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error in creating QThread and Pthread

    hi thanks for your reply.. see am gonna use qthreads now, okay what i need to change here??? i need:

    Qthread should work independently in the widget class itself and also widget class should work independently apart from qthread..
    my problem is qobject cannot inherit more than once. so what i need to change in my code?? .. i ve verified example but i dint get proper solution so please help..

    thanks in advance,
    shakthi

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: error in creating QThread and Pthread

    This:

    Qt Code:
    1. class mythread:public QThreads,public Widget
    To copy to clipboard, switch view to plain text mode 

    is not correct in "Qt terms"

    Widgets live in one thread only, usually the main application thread.
    You perform the operations in another thread and display it via a widget. This means you need to establish some communication between (a) widget(s) and (a) thread(s).

  5. #5
    Join Date
    Jul 2011
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error in creating QThread and Pthread

    yes actually i like to import some object from widget class.. like ui->textedit->settext like that.. for that i must import from widget class.. ok what i need to change? i cant avoid multiple inheritance... any other suggestions??

Similar Threads

  1. qt-4.5.3 linking issue (excessive pthread)
    By Ronayn in forum Qt Programming
    Replies: 1
    Last Post: 7th April 2011, 14:48
  2. Error while creating a plugin for Qt
    By panpaliamahen in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2010, 19:12
  3. -pthread havoc
    By Cruz in forum Qt Programming
    Replies: 8
    Last Post: 10th March 2010, 12:22
  4. QThread Error
    By QbelcorT in forum Qt Programming
    Replies: 1
    Last Post: 23rd June 2009, 10:22
  5. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16

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.