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. QObject::connect: No such slot QWidget::showTimee()
QtWS25 Last Chance

QObject::connect: No such slot QWidget::showTimee()

Scheduled Pinned Locked Moved General and Desktop
9 Posts 7 Posters 3.0k 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.
  • A Offline
    A Offline
    AQTStudent
    wrote on last edited by
    #1

    My error:
    QObject::connect: No such slot QWidget::showTimee() in ../TUecomotivefinal/digitalclock.cpp:11

    digitalclock.h:

    #ifndef DIGITALCLOCK_H
    #define DIGITALCLOCK_H
    #include <QWidget>
    class DigitalClock : public QWidget
    {
    public:
        DigitalClock(QWidget *parent = 0);
    public slots:
        void showTimee();
    private:
    };
    #endif // DIGITALCLOCK_H
    

    digitalclock.cpp

    #include "digitalclock.h"
    #include <QDebug>
    #include <QtWidgets>
    #include <QObject>
    DigitalClock::DigitalClock(QWidget *parent)
        : QWidget(parent)
    {
        QTimer *timer2 = new QTimer(this);
        QObject::connect(timer2, SIGNAL(timeout()), this, SLOT(showTimee()));
        timer2->start(10000);
    }
    void DigitalClock::showTimee(){
            QTime time = QTime::currentTime();
            QString text = time.toString("hh:mm");
            qDebug() << text;
    }
    

    I am kind of new to C++ and new to QT.. I'm hoping someone can help. Thanks in advance!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      you have to add Q_OBJECT in your class declaration

      #ifndef DIGITALCLOCK_H
      #define DIGITALCLOCK_H
      #include <QWidget>
      class DigitalClock : public QWidget
      {
          Q_OBJECT
      
      public:
          DigitalClock(QWidget *parent = 0);
      public slots:
          void showTimee();
      private:
      };
      #endif // DIGITALCLOCK_H
      

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      A B 2 Replies Last reply
      3
      • M mcosta

        Hi,

        you have to add Q_OBJECT in your class declaration

        #ifndef DIGITALCLOCK_H
        #define DIGITALCLOCK_H
        #include <QWidget>
        class DigitalClock : public QWidget
        {
            Q_OBJECT
        
        public:
            DigitalClock(QWidget *parent = 0);
        public slots:
            void showTimee();
        private:
        };
        #endif // DIGITALCLOCK_H
        
        A Offline
        A Offline
        AQTStudent
        wrote on last edited by
        #3

        @mcosta
        Nice! This solved it!
        Can you explain why I need to set this?
        Knowing the solution is one, but understanding is more important ;p

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #4

          Hi,
          the Q_OBJECT macro is used to tell the MOC (meta object compiler) that a particular class uses Qt's signals and slots mechanism.

          1 Reply Last reply
          1
          • M Offline
            M Offline
            mcosta
            wrote on last edited by
            #5

            Hi,

            you can found more information here and here

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            1 Reply Last reply
            0
            • M mcosta

              Hi,

              you have to add Q_OBJECT in your class declaration

              #ifndef DIGITALCLOCK_H
              #define DIGITALCLOCK_H
              #include <QWidget>
              class DigitalClock : public QWidget
              {
                  Q_OBJECT
              
              public:
                  DigitalClock(QWidget *parent = 0);
              public slots:
                  void showTimee();
              private:
              };
              #endif // DIGITALCLOCK_H
              
              B Offline
              B Offline
              briantranscend
              wrote on last edited by
              #6

              @mcosta I do have !_Object added to my class declaration and yet the issue persists

              mrjjM SGaistS Pablo J. RoginaP 3 Replies Last reply
              0
              • B briantranscend

                @mcosta I do have !_Object added to my class declaration and yet the issue persists

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @briantranscend
                Hi
                if it still persists then go to the build folder and delete all files.
                then rebuild

                1 Reply Last reply
                0
                • B briantranscend

                  @mcosta I do have !_Object added to my class declaration and yet the issue persists

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @briantranscend hi and welcome to devnet,

                  Did you re-run qmake after adding the Q_OBJECT macro ?

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

                  1 Reply Last reply
                  1
                  • B briantranscend

                    @mcosta I do have !_Object added to my class declaration and yet the issue persists

                    Pablo J. RoginaP Offline
                    Pablo J. RoginaP Offline
                    Pablo J. Rogina
                    wrote on last edited by
                    #9

                    @briantranscend please take a look at the new syntax for signals & slots
                    It'll help you catch errors at compile time...

                    Upvote the answer(s) that helped you solve the issue
                    Use "Topic Tools" button to mark your post as Solved
                    Add screenshots via postimage.org
                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                    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