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. Creating pthread in qt creator

Creating pthread in qt creator

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 4.4k 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.
  • P Offline
    P Offline
    pirpi
    wrote on last edited by
    #1

    Hi all,
    I am a newbie, I just want to send some messages from pthreads thread function to qt GUI. I am creating thread like this
    pthread_create(&thread_read, NULL,&read_data,NULL);.
    But I am getting following error
    " read_data is not declared in this scope".
    I have added
    QMAKE_CXXFLAGS+= -std=gnu++0x -pthread -lpthread
    LIBS += -L/usr/include -pthread

    in .pro file in the project. Could anybody help me with this?

    Thanks
    pirpi

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Where is read_data located ?

      Also, since you are using Qt, why not take advantage of QThread which is cross-plaform ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pirpi
        wrote on last edited by
        #3

        No, already I have done a program using posix thread. I just want to send some message from posix threads to qt gui. For that purpose I just want to use posix thread.

        read_data is located in main.cpp. I am defining read_data like this

        void *read_data()
        {
        cout<<"Hello"<<endl;
        }

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          And where do you create the pthread ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pirpi
            wrote on last edited by
            #5

            I have created pthread in main(). I am creating like this
            pthread_create(&thread_read, NULL,&read_data,NULL); and I am defining read_data in the same main.cpp like this void * read_data().
            Could you please help me with this.

            Thanks
            pirpi

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Can you show your complete code ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

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