Results 1 to 6 of 6

Thread: Can't make Q_INVOKABLE macro use compile

  1. #1
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Can't make Q_INVOKABLE macro use compile

    I'm trying to create an object for use for QML integration.

    If I uncomment the marked code, I get compilation errors:
    Qt Code:
    1. // header
    2. #ifndef MY_QML_INTERFACE_H
    3. #define MY_QML_INTERFACE_H
    4.  
    5. #include <QObject>
    6. #include <QDateTime>
    7.  
    8. class MyQmlInterface : public QObject
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13.  
    14. Q_PROPERTY(QString singleValue READ singleValue WRITE setSingleValue NOTIFY singleValueChanged);
    15.  
    16. const QString &singleValue() const;
    17. void setSingleValue(const QString &newSingleValue);
    18.  
    19. /* THIS CODE WON't COMPILE
    20. Q_INVOKABLE QDateTime getCurrentDateTime() const {
    21.   return QDateTime::currentDateTime();
    22. */
    23.  
    24. signals:
    25. void singleValueChanged();
    26. private:
    27. QString mSingleValue;
    28. };
    29.  
    30. #endif
    31.  
    32. // Cpp
    33. #include "MyQmlInterface.h"
    34.  
    35. const QString &MyQmlInterface::singleValue() const
    36. {
    37. return mSingleValue;
    38. }
    39.  
    40. void MyQmlInterface::setSingleValue(const QString &newSingleValue)
    41. {
    42. if (newSingleValue == mSingleValue)
    43. return;
    44. mSingleValue = newSingleValue;
    45. emit singleValueChanged();
    46. }
    To copy to clipboard, switch view to plain text mode 

    Any idea why this doesn't work?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't make Q_INVOKABLE macro use compile

    What is the error you get? Did you remember to run qmake?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't make Q_INVOKABLE macro use compile

    This is happening in visual studio.

    I get this warning in the output:
    "MyQmlInterface.h(28): Warning: No relevant classes found. No output generated."
    And then a bunch of compilation errors for different classes of mine.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't make Q_INVOKABLE macro use compile

    The code looks correct. Could you prepare a minimal compilable (well, almost) example reproducing the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    frankiefrank (22nd September 2011)

  6. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Can't make Q_INVOKABLE macro use compile

    I assume the closing bracket is not missing in your final code ?
    Qt Code:
    1. /* THIS CODE WON't COMPILE
    2. Q_INVOKABLE QDateTime getCurrentDateTime() const {
    3.   return QDateTime::currentDateTime();
    4. } // <- this closing bracket */
    To copy to clipboard, switch view to plain text mode 

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

    frankiefrank (22nd September 2011)

  8. #6
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't make Q_INVOKABLE macro use compile

    Thank you stampede! Goddamit! :-)

    And thanks wysota for your time as well!

Similar Threads

  1. compile / link error mingw-make release
    By jm in forum Installation and Deployment
    Replies: 8
    Last Post: 30th June 2010, 15:07
  2. Problem using Q_INVOKABLE on private constructor
    By graeme in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2010, 21:50
  3. make error when compile qtopia 4.2.4
    By evewei in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd November 2007, 11:44
  4. Qtopia core 4.2.2 cross compile make error
    By smiyai18 in forum Installation and Deployment
    Replies: 2
    Last Post: 28th August 2007, 17:04
  5. Macro
    By comlink21 in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2007, 11:28

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.