Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error in creating Qthreads and pthread
Forum Updated to NodeBB v4.3 + New Features

Error in creating Qthreads and pthread

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shakthi
    wrote on 29 Jul 2011, 02:50 last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 29 Jul 2011, 05:42 last edited by
      #2

      Hi,

      your problem is multiple inheritance:

      @
      class mythread:public QThreads,public Widget
      {};
      @

      As I read your threda, if not Linux, which is your target platform here? Windows? if yes, pthread does not exist there. Using QTHread is the easiest way here, but not as base class for a widget.

      Create an own thread class and a widget class and make the thread a member of the widget if they are tighly coupled. But the widget has to live in the main thread.

      You can read more on QTHread in "peppes article":http://developer.qt.nokia.com/wiki/ThreadsEventsQObjects

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on 29 Jul 2011, 11:30 last edited by
        #3

        [quote author="shakthi" date="1311907824"]
        @class mythread:public QThreads,public Widget
        {
        public:
        void run();
        }@
        [/quote]

        Apart from the typos, if that Widget is actually a QWidget subclass, you're doing two serious mistakes here:

        you cannot inherit from QObject more than once

        you can't use ANY GUI code* in other threads but the main thread

        Please elaborate if you want more help.

        *namely, code that uses server-side features (widgets, pixmaps, possibly fonts, etc.).

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shakthi
          wrote on 30 Jul 2011, 08:28 last edited by
          #4

          hi thanks for your reply.. see am gonna use qthreads now, okay what i need to change here??? with out do multiple inheritance i cant import the objects like pushbutton, labels from widget class.. see i have clearly defined, am gonna use thread for multiple client and server connection..... i need:

          Qthread should work independently in the widget class itself and also widget class should work independently apart from qthread..
          yes qobject cannot inherit more than once. so what i need to change in my code?? please help

          thanks in advance,
          shakthi

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on 30 Jul 2011, 11:35 last edited by
            #5

            Hi shakthi,

            perhaps we should start a bit earlier, before you decide what to put to a thread.

            What exactly do you want to achieve?
            How should your app look like?
            If you really nee threads, think carefully where to use them and in which way. Is it a widget that wants to get the data inside a thread? then the thread could be a member of the widget for example.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              shakthi
              wrote on 30 Jul 2011, 15:33 last edited by
              #6

              hi,

              actually i have implemented client-server application which will read only if we press read button in client side and server side but now i ve designed normal chat messenger so i used qthreads to implement which can read from server and also server should read from client independently.. so i used qthreads and also imported widget class which has subclass of qwidget . but while executing i got some unknown error like debugger crashed , couldn't find it.. code i ve already posted above. in mythread class just done multiple inheritence with base class of qthread and widget class and declared run function alone and in .cpp file created thread object and use start function to initiate run function where i have defined widget object function.. hope now everyone understand.. please help me to find out the error and just give me the suggestion to use qthread

              thanks in advance,
              shakthi

              1 Reply Last reply
              0

              1/6

              29 Jul 2011, 02:50

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved