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. Custome destructor in C++

Custome destructor in C++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 3 Posters 1.3k Views 3 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.
  • AhtiA Offline
    AhtiA Offline
    Ahti
    wrote on last edited by
    #1

    I am developing an app in which I start a timer in constructor and stop it in destructor but I get an error namely:

    'class Example' has no member named 'level'.

    My Code:

    Example.h

    class Example: public QObject
    {
        Q_OBJECT
    
        public:
    
            explicit Example(QObject *parent = 0);    
            ~Example();
        ... 
    }
    

    Example.cpp:

    Example::Example(QObject *parent) : QObject(parent)
    {
        timer = new QTimer(this);
        connect(timer, SIGNAL(timeout()),this,SLOT(update_func()));
        timer->start(1000);
    }
    
    Example::~Example(){
        timer->stop();
    }
    

    please help.

    what is a signature ?? Lol

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you have any "level" variable somewhere that you are calling ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      AhtiA 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        Do you have any "level" variable somewhere that you are calling ?

        AhtiA Offline
        AhtiA Offline
        Ahti
        wrote on last edited by
        #3

        @SGaist yes in header this:

        Q_PROPERTY(int level READ level WRITE set_level NOTIFY level_changed)
        

        what is a signature ?? Lol

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you properly declare all the methods and implement the slot and getter ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          AhtiA 1 Reply Last reply
          1
          • SGaistS SGaist

            Did you properly declare all the methods and implement the slot and getter ?

            AhtiA Offline
            AhtiA Offline
            Ahti
            wrote on last edited by Ahti
            #5

            @SGaist I think so:

            void Example::set_level(int level){
                if (level != g_level){
                    g_level = level;
                    emit level_changed(g_level);
                }
            }
            
            void Example::update_func(){
                int level = get_level();
                if (level != INVALID){
                    set_level(level);
                }
            }
            
            int Example::cur_level(){
                return g_level;
            }
            

            what is a signature ?? Lol

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You declared the getter method to be level. I don't see that method anywhere in your code.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              AhtiA 1 Reply Last reply
              2
              • SGaistS SGaist

                You declared the getter method to be level. I don't see that method anywhere in your code.

                AhtiA Offline
                AhtiA Offline
                Ahti
                wrote on last edited by
                #7

                @SGaist What Is a getter ?

                what is a signature ?? Lol

                JKSHJ 1 Reply Last reply
                0
                • AhtiA Ahti

                  @SGaist What Is a getter ?

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  @Ahti said in Custome destructor in C++:

                  What Is a getter ?

                  In your header, you wrote this:

                  Q_PROPERTY(int level READ level WRITE set_level NOTIFY level_changed)
                  

                  You're saying that you have these functions:

                  • Getter method (READ): level()
                  • Setter method (WRITE): set_level()
                  • Signal (NOTIFY): level_changed()

                  You told Qt that your getter is called level(), but it is actually called cur_level().

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  AhtiA 1 Reply Last reply
                  4
                  • JKSHJ JKSH

                    @Ahti said in Custome destructor in C++:

                    What Is a getter ?

                    In your header, you wrote this:

                    Q_PROPERTY(int level READ level WRITE set_level NOTIFY level_changed)
                    

                    You're saying that you have these functions:

                    • Getter method (READ): level()
                    • Setter method (WRITE): set_level()
                    • Signal (NOTIFY): level_changed()

                    You told Qt that your getter is called level(), but it is actually called cur_level().

                    AhtiA Offline
                    AhtiA Offline
                    Ahti
                    wrote on last edited by
                    #9

                    @JKSH @SGaist Please answer this question https://forum.qt.io/topic/104014/how-to-update-qml-control-periodically-from-c-code/2

                    what is a signature ?? Lol

                    1 Reply Last reply
                    -3

                    • Login

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