Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED]C++ class with QML
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]C++ class with QML

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.1k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    Javeria
    wrote on last edited by
    #1

    Hello i ve recently made a demo class to test if i can declare its object in main:
    Butit gives me unresolved external error, here is the header file:
    @
    #ifndef DETECTSQUARES_H
    #define DETECTSQUARES_H

    #include <QObject>

    class DetectSquares: public QObject
    {
    Q_OBJECT
    Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
    public:
    explicit DetectSquares(QObject *parent=0);
    ~DetectSquares();
    };

    #endif // DETECTSQUARES_H
    @

    I get error when i declare
    DetectSquares r;

    [Edited - Please use code tags "@@" - p3c0]

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      It seems you have not defined the functions for the property author. Just right click on Q_PROPERTY and click "Generate missiin Q_PROPERTY members".

      157

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Javeria
        wrote on last edited by
        #3

        @@ class DetectSquares: public QObject
        {
        Q_OBJECT
        public:
        void Draw();
        }; @@

        I made it simple but if i call it in the main function like this :
        @@ DetectSquares * r();
        r.Draw(); @@

        I get error .Draw must have class/struct/union

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Since you are decalring it a pointer it should be
          @
          DetectSquares *r;
          r->Draw();
          @

          or keep it on stack
          @
          DetectSquares r;
          r.Draw();
          @

          157

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koval
            wrote on last edited by
            #5

            If you choose to use a pointer do not forget to create the object.
            Even if that compiles you will get a crash because r does not point to a valid object.
            Even better use an automatic pointer to avoid memory leaks:
            @QScopedPointer<DetectSquares> r(new DetectSquares());
            r->Draw();@

            1 Reply Last reply
            0

            • Login

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