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. Purple Error in Widget Project
Forum Updated to NodeBB v4.3 + New Features

Purple Error in Widget Project

Scheduled Pinned Locked Moved General and Desktop
17 Posts 2 Posters 5.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.
  • F Offline
    F Offline
    Flurite
    wrote on last edited by
    #1

    Hi,

    In order to simplify one of my widget projects, I decided to divide my declarations and definitions of my classes and their members for specific sections into various headers and cpp files. Problem is, that now I did that, I get a purple error when I run my code.

    This is the error:

    @
    Object::connect: No such slot Clock_Application::timer_Start() in ./ui_clock_application.h:101
    Object::connect: (sender name: 'Start')
    Object::connect: (receiver name: 'Clock_Application')
    Object::connect: No such slot Clock_Application::timer_Stop() in ./ui_clock_application.h:102
    Object::connect: (sender name: 'Pause')
    Object::connect: (receiver name: 'Clock_Application')
    Object::connect: No such slot Clock_Application::timer_Reset() in ./ui_clock_application.h:103
    Object::connect: (sender name: 'Reset')
    Object::connect: (receiver name: 'Clock_Application')
    @

    This problem, I realized, was caused by moving my slot declarations outside of the class where I had them in. How would I go about allowing my slots to be declared in other classes besides MainWindow?

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

      Slots can be defined in any class which is QObject-based. However, in your connect statement, you have to make sure that the object pointed to is the same type of object that contains your slot.

      Without seeing the code changes you've made, it's hard to tell what you're doing.

      I think you might be served well by a good review of signals and slots, in general, as it feels like you might not have a full grasp of the operation of them. Have you read "this documentation":/doc/qt-4.8/signalsandslots.html about them?

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Flurite
        wrote on last edited by
        #3

        I believe I connected it right. This is my connection:

        @
        void Stopwatch::timer_Start()
        {
        stopwatchTimer = new QTimer();
        connect(stopwatchTimer, SIGNAL(timeout()), this, SLOT(timer_changeTime()));
        stopwatchTimer->start(1000);
        }
        @

        This is my class:

        @
        class Stopwatch : public QObject
        {
        Q_OBJECT
        public:
        Stopwatch();
        private slots:
        void timer_Start();
        void timer_Stop();
        void timer_Reset();

        void timer_changeTime();
        

        private:
        QTimer* stopwatchTimer;
        };
        @

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          Looking at the output, you can see that the errors are being generated from ui_clock_application.h, though. Unless your Stopwatch class is defined in ui_clock_application.h, then you're looking in the wrong place.

          As an aside, you have a memory leak in your timer_Start() slot. You are creating a new QTimer every time the slot is called. This is bad, because when you create a new one, the old one still exists.

          In your Stopwatch constructor, you should have the line:
          @
          stopwatchTimer = 0; // or NULL
          @

          And then in timer_Start():
          @
          void Stopwatch::timer_Start()
          {
          if (!stopwatchTimer) // Only do this stuff if it hasn't been done before.
          {
          stopwatchTimer = new QTimer();
          connect(stopwatchTimer, SIGNAL(timeout()), this, SLOT(timer_changeTime()));
          }
          stopwatchTimer->start(1000);
          }
          @

          (Alternately, you could move the creation and connection of the QTimer into the constructor, and just call stopwatchTimer->start(...) from your slot.)

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Flurite
            wrote on last edited by
            #5

            Yeah, the errors are generated in that file, but you cannot save changes to that file.

            I will try and fix up that memory leak you mentioned. Thanks.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              True, you can't save changes to that file, but those items are generated from your .ui file. Make sure that in the .ui file that any signal/slot connections you are making are pointing at the right objects.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • F Offline
                F Offline
                Flurite
                wrote on last edited by
                #7

                The arrows are all pointing at the MainWindow (or Clock_Application), so this is what made me wonder whether you can only declare slots in the MainWindow (or Clock_Application) class.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on last edited by
                  #8

                  There's nothing magical about MainWindow or Clock_Application or anything like that. There's just a connection being made somewhere (looks like in your .ui file) which is still expecting the timer_Start() slot (etc.) to be in the old location. Just moving the slot definition isn't enough to make the .ui file look point to the right place.

                  What are you doing in the clock_application.ui file which calls timer_Start()? What triggers timer_Start() to be called?

                  Software Engineer
                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    Flurite
                    wrote on last edited by
                    #9

                    timer_Start() is triggered by a click of a button in the widget application. The button is a simple QPushButton.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mlong
                      wrote on last edited by
                      #10

                      Where is the connection made?

                      Software Engineer
                      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        Flurite
                        wrote on last edited by
                        #11

                        When you say "connection" do you refer to my connect() function? If so, here it is:

                        @
                        void Stopwatch::timer_Start()
                        {
                        stopwatchTimer = new QTimer();
                        connect(stopwatchTimer, SIGNAL(timeout()), this, SLOT(timer_changeTime()));
                        stopwatchTimer->start(1000);
                        }
                        @

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mlong
                          wrote on last edited by
                          #12

                          No. What makes the button call timer_Start(). How do you tell it to do this?

                          Software Engineer
                          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            Flurite
                            wrote on last edited by
                            #13

                            I use that one menu in Qt Designer that allows you to draw blue/red arrows. I then create a new slot, and call it "timer_Start()", and I believe, this automatically connects the clicked() signal and the timer_Start() slot.

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mlong
                              wrote on last edited by
                              #14

                              The arrows need to point to Stopwatch, not Clock_Application, if the slots are defined in Stopwatch.

                              Behind the scenes, those arrows translate to a "connect()" call in the ui_clock_application.h file.

                              Software Engineer
                              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                              1 Reply Last reply
                              0
                              • F Offline
                                F Offline
                                Flurite
                                wrote on last edited by
                                #15

                                How do I get it to "point" to Stopwatch? Stopwatch is just a class. It does not really refer to any widget.

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mlong
                                  wrote on last edited by
                                  #16

                                  Ah. Good point. In that case, I'd say that there shouldn't be any arrows anywhere, and that you should make the connection in code.

                                  Edit to add:

                                  Alternately, you could keep "proxy" slots in your Clock_Application widget, and from within those slots just call the slots in Stopwatch.

                                  That is to say:
                                  @
                                  class Clock_Application ...
                                  {
                                  Q_OBJECT
                                  ...
                                  public slots:
                                  void timer_Start() { m_stopwatch->timer_Start(); } // just "pass through" to your Stopwatch class. (Remember that slots are just plain old methods too, and can be directly called like any other method.)
                                  ...
                                  private:
                                  Stopwatch *m_stopwatch;
                                  };
                                  @

                                  Software Engineer
                                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                                  1 Reply Last reply
                                  0
                                  • F Offline
                                    F Offline
                                    Flurite
                                    wrote on last edited by
                                    #17

                                    Hmm.. now I am receiving a strange error:

                                    multiple definition of ui
                                    first defined here
                                    collect2: Id returned 1 exit status

                                    The lines in where the errors occur do not seem to be in my project, but in other files.. possibly library files? It's also strange, because I have defined my own ui just previously, and am wondering what is causing it now.

                                    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