Results 1 to 11 of 11

Thread: I can not do a signal working

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default I can not do a signal working

    Hi I have a clas ( inherited from QObject ) containing a signal.
    When I try compile ( with visual studio 2008 ) I get the following error from the compiler:
    IrisKernel::sig_userRecognized': invalid call of member function non-static
    ( translated from Italian ).

    This is the class declaration:


    Qt Code:
    1. class IrisKernel : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. IrisKernel(QObject *parent = 0);
    7. virtual ~IrisKernel();
    8.  
    9. static const QByteArray findMatchingPerson( KSBitVector&, double *mindist );
    10. static void onStoreIrisCodes(IplImage** imageList, QString& dni, bool storeImages);
    11.  
    12. signals:
    13. void sig_userRecognized(QByteArray&);
    14.  
    15. protected:
    16. private:
    17. int m_templateSize;
    18. bool m_validated;
    19. };
    To copy to clipboard, switch view to plain text mode 
    I don't get such error with other classes and the pro file is well edited.
    Which can be the error?
    Regards
    Franco Amato

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: I can not do a signal working

    The error is in your implementation, not your declaration. And the error message you posted tells you exactly what the problem is. Please review basic C++ rules on static members.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: I can not do a signal working

    Re-run qmake and then rebuild. Does the error persist?

    Edit: SixDegrees is on the money. I misread this as the usual "file has not been moc-ed" problem.

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: I can not do a signal working

    Is the error code C2352? Then how do you call (emit) the signal?
    Like this emit IrisKernel::sig_userRecognized(...);?
    Then lose the IrisKernel:: and call emit sig_userRecognized(...);

  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I can not do a signal working

    Quote Originally Posted by ChrisW67 View Post
    Re-run qmake and then rebuild. Does the error persist?

    Edit: SixDegrees is on the money. I misread this as the usual "file has not been moc-ed" problem.
    Quote Originally Posted by ChrisW67 View Post
    Re-run qmake and then rebuild. Does the error persist?
    Hi yes.
    I deleted all visual-studio related files, then I re-run qmake so:
    qmake -tp vc myfile.pro
    They I built the created solution and the error persist.
    Maybe I can not mix static functions and signals into the same class?
    Regards

    Quote Originally Posted by Zlatomir View Post
    Is the error code C2352? Then how do you call (emit) the signal?
    Like this emit IrisKernel::sig_userRecognized(...);?
    Then lose the IrisKernel:: and call emit sig_userRecognized(...);
    The error is this:
    error C2352: 'IrisKernel::sig_userRecognized': chiamata non valida di funzione membro non statica
    English translation: call not valid to a non-static function
    Franco Amato

  6. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: I can not do a signal working

    I assumed you have an object, don't just try to emit the signal from a static method or try to create a "static" signal.

  7. The following user says thank you to Zlatomir for this useful post:

    franco.amato (4th February 2011)

  8. #7
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I can not do a signal working

    Quote Originally Posted by Zlatomir View Post
    I assumed you have an object, don't just try to emit the signal from a static method or try to create a "static" signal.
    Yes I emit the signal inside a static member. Is this a problem?


    Added after 11 minutes:


    I changed the method calling the signal from static to non-static and now I don't get the error.
    I didn't know that.
    I also tried to declare a static signal so:
    signals:
    static void sameName(SameParams);

    but seems the compiler doesn't like it.
    I got this new error:
    error C2671: 'IrisKernel::sig_userRecognized': le funzioni membro statiche non hanno puntatori 'this'
    english translation: static members doesn't have 'this' pointers

    I think the only way is to call the non-static signal from a non-static method.

    Regards
    Last edited by franco.amato; 4th February 2011 at 01:07.
    Franco Amato

  9. #8
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: I can not do a signal working

    Well...
    Qt's meta-object system provides the signals and slots mechanism for inter-object communication, run-time type information, and the dynamic property system...
    From here
    How to communicate between objects if you don't have an object?
    And run-time doesn't "interact" well with static (is like you want a static virtual function)

    So you will need to redesign your class, and create objects if you want to use signals and slots, else figure out how you can directly call functions.

    But anyway why those functions are static?

  10. #9
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I can not do a signal working

    Quote Originally Posted by Zlatomir View Post
    How to communicate between objects if you don't have an object?
    And run-time doesn't "interact" well with static (is like you want a static virtual function)

    So you will need to redesign your class, and create objects if you want to use signals and slots, else figure out how you can directly call functions.

    But anyway why those functions are static?
    Hi thank you very much ( I should improve my c++ knowledge )
    I declared them static because I don't really need an object to call such methods.
    The methods only work on the params I pass and the class doesn't have any role in the classes diagram.
    Franco Amato

  11. #10
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: I can not do a signal working

    You definitely need an object if you want signals and slots.

  12. The following user says thank you to Zlatomir for this useful post:

    franco.amato (4th February 2011)

  13. #11
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: I can not do a signal working

    I don't know if I got Your problem correctly. Sorry, if I did not
    But I also have some static methods from which I need to emit the signals
    my methods need to be static, because I hold pointers to them inside the array
    I emit the signal from within the static method using the static selfPointer
    like this
    Qt Code:
    1. emit staticSelfPtr->mySignal()
    To copy to clipboard, switch view to plain text mode 

    I do not know how correct this "workaround" is, but is working and I simply need to emit the signal from method which has to be static
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

Similar Threads

  1. QFutureWatcher finished() signal not working
    By DiamonDogX in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2011, 18:27
  2. Signal and Slot connection not working !!
    By prakash437 in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2010, 10:16
  3. QObject signal/slot not working
    By Msnforum in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2009, 22:50
  4. Signal Slot not working
    By munna in forum Qt Programming
    Replies: 8
    Last Post: 6th November 2006, 10:36
  5. QTreeWidget signal not working
    By Kapil in forum Newbie
    Replies: 6
    Last Post: 28th April 2006, 10:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.