PDA

View Full Version : Integrating Pthread Library with QT



bandarus
29th January 2017, 23:53
In my project is based on the Linux OS and I have two parts of code.

One GUI implemented with QT and the other part is Libraries implemented using Standard C++(these libraries used across multiple systems to communicate, We can't replace with Qthreads) using pthread.

To make Qt successfully call the library, I add "-lpthread" in Qt's .pro file.

When I run Qt, problems come. Sometimes Qt is crashing in GUI update function.

ProcessStatusDetails function is called pthred to update the status on to GUI


int ProcessStatusDetails(StatusDetails* Status,std::string& StatusMsg)
{
int Erc;

pthread_mutex_lock( &mutex1 );
Erc = pMainWindow->UpdateGuiDetails(PisStatus,StatusMsg);
pthread_mutex_unlock( &mutex1 );

}

Could some one help me how to signal the GUI update from Pthread function.?

Lesiok
30th January 2017, 07:14
GUI allowed to operate only in the main thread.

anda_skoa
30th January 2017, 09:38
To make Qt successfully call the library, I add "-lpthread" in Qt's .pro file.

Not sure why this would be necessary, Qt already links with libpthread.



Could some one help me how to signal the GUI update from Pthread function.?

Via a signal connected to a slot of an object on the GUI thread or by calling a slot of such an object via QMetaObject::invokeMethod() with connection type Qt::QueuedConnection or by posting a custom event to an object on the GUI thread.

Cheers,
_