我为自己的目的编写了这段代码。它将创建一个线程来运行名为 event_handler() 的例程。例程 event_handler 将类对象 QApplication 的实例作为参数并调用其 exec() 方法。
#include <pthread.h>
void event_handler(void * &obj)
{
QApplication* app = reinterpret_cast<QApplication*>(&obj);
app.exec();
}
int main(int argc, char **argv)
{
pthread_t p1;
QApplication a(argc, argv);
pthread_create(&p1, NULL, &event_handler,(void *) &a);
//do some computation which will be performed by main thread
pthread_join(*p1,NULL);
}
但是每当我尝试构建这段代码时,我都会收到此错误
main.cpp:10: error: request for member ‘exec’ in ‘app’, which is of non-class type ‘QApplication*’
main.cpp:34: error: invalid conversion from ‘void (*)(void*&)’ to ‘void* (*)(void*)’
main.cpp:34: error: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’
我的代码有什么问题。(请记住,我是该领域的新手,这可能是一个非常愚蠢的错误:-))