QPixmap- It is not safe to use QPixmap outside the gui Thread



  • in main function my dialog is displayed
    and i have created a new pthread as follows

    pthread_t t1;
    pthread_create(&t1,NULL,&message,NULL);

    void * message(void *)
    {
    // data for receiving the buffer on udp
    //after receiving
    dialog d; // my gui
    d.display(buffer); // sending the received buffer to the gui function for displaying the values on the labels

    }

    when i run this code am getting the following error

    QPixmap- It is not safe to use QPixmap outside the gui Thread

    i have not used QPixmap then why this error
    am able to print the received data at the console but not able to set the text on the gui labels

    can any one suggest why

    }

    `


  • Lifetime Qt Champion

    Hi,

    You are using GUI elements outside the GUI thread and that's not allowed. You'll have to send your buffer to your main thread and from there show your dialog.

    Also, please enclose your code in coding tags (first icon to the right) so it's more readable :)



  • my main thread code is as follows
    @
    main.cpp
    @

    int main()
    {

    QApplication a;
    Ground gs; // dialog name
    gs.show();
    return a.exec():
    }
    now my question how should i send it to main thread


  • Moderators

    Signals and slots can safely transfer data across threads


Log in to reply
 

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