[SOLVED]QT Slot trying to call void* foo(void*) for a pthread falied.
-
Hello, I am trying to start a new pthread from a QT program. Here is what I am doing: I have a slot callDirwalk() which performs the following task:
@
void SimpleGUI::callDirwalk() {#ifdef gnu_linux
//thread main()
int err;
pthread_t t = getPThreadFromDirwalker();
err = pthread_create(&t, NULL, &doSomething, NULL);
sleep(2);
#endif
}
@
I am recieving the following error messages:
@
/home/ilian/QT5/SampleGame/SimpleGUI.cpp:73: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&SimpleGUI::doSomething' [-fpermissive]
err = pthread_create(&t, NULL, &doSomething, NULL);
^
@
and:
@/home/ilian/QT5/SampleGame/SimpleGUI.cpp:73: error: cannot convert 'void (SimpleGUI::)()' to 'void ()(void)' for argument '3' to 'int pthread_create(pthread_t*, const pthread_attr_t*, void* ()(void), void*)'
err = pthread_create(&t, NULL, &doSomething, NULL);
^
@How can I fix that?
-
The error says it all. You can't pass a non-static member function as a function pointer to pthread_create.
Either make doSomething a static member or a free standing function.On another hand, since you're using Qt anyway why not use QThread instead?
-
[EDIT] Actually it was a naming collision with a private function doSomething in QT interface, I
ve renamed it to doSomething2 and it was ok... dull :( Your suggestion is good about QThread, but I want to have a separate daemon object, which thread will be started with QT button press. Actually doSomething is a free standing member of Dirwalk.h which is included in the QTGui.h I
ve made. It`s a global function that should be called from everywhere.