Creating pthread in qt creator



  • 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


  • Lifetime Qt Champion

    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 ?



  • 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;
    }


  • Lifetime Qt Champion

    And where do you create the pthread ?



  • 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


  • Lifetime Qt Champion

    Can you show your complete code ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.