Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]QT Slot trying to call void* foo(void*) for a pthread falied.
QtWS25 Last Chance

[SOLVED]QT Slot trying to call void* foo(void*) for a pthread falied.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    heatblazer
    wrote on 14 Sept 2014, 12:29 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisaverage
      wrote on 14 Sept 2014, 13:16 last edited by
      #2

      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?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        heatblazer
        wrote on 14 Sept 2014, 14:10 last edited by
        #3

        [EDIT] Actually it was a naming collision with a private function doSomething in QT interface, Ive 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 Ive made. It`s a global function that should be called from everywhere.

        1 Reply Last reply
        0

        3/3

        14 Sept 2014, 14:10

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved