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. Using Signals and Slots
Forum Updated to NodeBB v4.3 + New Features

Using Signals and Slots

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 5 Posters 4.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.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #3

    To add to jsulm

    you need code to emit the signal or you can connect it to another signal (e.g. of QSlider).

    Vote the answer(s) that helped you to solve your issue(s)

    J.HilkJ 1 Reply Last reply
    0
    • jsulmJ jsulm

      @JimmyMars said in Using Signals and Slots:

      Do I have to write the definition of valueChanged() as a signal?

      No, you only declare it in your class as signal, definition is done by moc compiler.
      Remove this:

      void Slider::valueChanged(int newValue){
          m_slider->valueChanged(newValue);
      }
      

      Regarding your errors: what Qt version? Operating system? Do you use QtCreator? Please post the whole error messages.

      JimmyMarsJ Offline
      JimmyMarsJ Offline
      JimmyMars
      wrote on last edited by
      #4

      @jsulm
      Qt 5.8.0 (Clang 7.0 (Apple))
      macOS Sierra
      QtCrreator 4.3.0

      That was the whole error message:
      0_1496997920787_Screen Shot 2017-06-09 at 10.44.31.png

      jsulmJ 1 Reply Last reply
      0
      • JimmyMarsJ JimmyMars

        @jsulm
        Qt 5.8.0 (Clang 7.0 (Apple))
        macOS Sierra
        QtCrreator 4.3.0

        That was the whole error message:
        0_1496997920787_Screen Shot 2017-06-09 at 10.44.31.png

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #5

        @JimmyMars Please go to "Compile Output" to get whole error messages.
        But first change the code as I said.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        JimmyMarsJ 1 Reply Last reply
        0
        • jsulmJ jsulm

          @JimmyMars Please go to "Compile Output" to get whole error messages.
          But first change the code as I said.

          JimmyMarsJ Offline
          JimmyMarsJ Offline
          JimmyMars
          wrote on last edited by
          #6

          @jsulm
          I have removed the definition of valueChanged now.

          Still getting this error:

          0:50:34: Running steps for project lab-slider...
          10:50:34: Configuration unchanged, skipping qmake step.
          10:50:34: Starting: "/usr/bin/make" 
          /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -stdlib=libc++ -headerpad_max_install_names  -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wl,-rpath,@executable_path/Frameworks -Wl,-rpath,/Users/gautam/Qt/5.9/clang_64/lib -o lab-slider.app/Contents/MacOS/lab-slider main.o slider.o   -F/Users/gautam/Qt/5.9/clang_64/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL 
          Undefined symbols for architecture x86_64:
            "vtable for Slider", referenced from:
                Slider::Slider(Qt::Orientation, QWidget*) in slider.o
            NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          make: *** [lab-slider.app/Contents/MacOS/lab-slider] Error 1
          10:50:34: The process "/usr/bin/make" exited with code 2.
          Error while building/deploying project lab-slider (kit: Desktop Qt 5.9.0 clang 64bit)
          When executing step "Make"
          10:50:34: Elapsed time: 00:00.
          
          jsulmJ 1 Reply Last reply
          0
          • K koahnig

            To add to jsulm

            you need code to emit the signal or you can connect it to another signal (e.g. of QSlider).

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #7

            @koahnig said in Using Signals and Slots:

            To add to jsulm

            you need code to emit the signal or you can connect it to another signal (e.g. of QSlider).

            isn't emit a placeholder? And emit mySignal(); acts the same as mySignal();

            But it gets quickly confusing if you omit the emit !


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            jsulmJ 1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @koahnig said in Using Signals and Slots:

              To add to jsulm

              you need code to emit the signal or you can connect it to another signal (e.g. of QSlider).

              isn't emit a placeholder? And emit mySignal(); acts the same as mySignal();

              But it gets quickly confusing if you omit the emit !

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @J.Hilk He means that the signal needs to be emitted somewhere

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • JimmyMarsJ JimmyMars

                @jsulm
                I have removed the definition of valueChanged now.

                Still getting this error:

                0:50:34: Running steps for project lab-slider...
                10:50:34: Configuration unchanged, skipping qmake step.
                10:50:34: Starting: "/usr/bin/make" 
                /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -stdlib=libc++ -headerpad_max_install_names  -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wl,-rpath,@executable_path/Frameworks -Wl,-rpath,/Users/gautam/Qt/5.9/clang_64/lib -o lab-slider.app/Contents/MacOS/lab-slider main.o slider.o   -F/Users/gautam/Qt/5.9/clang_64/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL 
                Undefined symbols for architecture x86_64:
                  "vtable for Slider", referenced from:
                      Slider::Slider(Qt::Orientation, QWidget*) in slider.o
                  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
                ld: symbol(s) not found for architecture x86_64
                clang: error: linker command failed with exit code 1 (use -v to see invocation)
                make: *** [lab-slider.app/Contents/MacOS/lab-slider] Error 1
                10:50:34: The process "/usr/bin/make" exited with code 2.
                Error while building/deploying project lab-slider (kit: Desktop Qt 5.9.0 clang 64bit)
                When executing step "Make"
                10:50:34: Elapsed time: 00:00.
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @JimmyMars How did you add Slider class? Manually or using QtCreator wizard?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                JimmyMarsJ 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @JimmyMars How did you add Slider class? Manually or using QtCreator wizard?

                  JimmyMarsJ Offline
                  JimmyMarsJ Offline
                  JimmyMars
                  wrote on last edited by
                  #10

                  @jsulm
                  I did it manually.

                  jsulmJ 2 Replies Last reply
                  0
                  • JimmyMarsJ JimmyMars

                    @jsulm
                    I did it manually.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @JimmyMars Then either read and follow http://doc.qt.io/qt-5.9/moc.html or do it using QtCreator wizard.
                    QObject derived classes need special handling using moc meta compiler from Qt. This isusually done for you, but not if you add a class manually.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • JimmyMarsJ JimmyMars

                      @jsulm
                      I did it manually.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @JimmyMars Actually it should work without any manual work if you use qmake.
                      Can you show your pro file?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      JimmyMarsJ 1 Reply Last reply
                      2
                      • jsulmJ jsulm

                        @JimmyMars Actually it should work without any manual work if you use qmake.
                        Can you show your pro file?

                        JimmyMarsJ Offline
                        JimmyMarsJ Offline
                        JimmyMars
                        wrote on last edited by
                        #13

                        @jsulm

                        I think there needs to be:
                        QT += core gui widgets

                        I have it currently like this.

                        HEADERS= slider.h
                        SOURCES= main.cpp slider.cpp
                        
                        OTHER_FILES += \
                            readme.txt
                        QT += widgets
                        
                        jsulmJ 1 Reply Last reply
                        1
                        • JimmyMarsJ JimmyMars

                          @jsulm

                          I think there needs to be:
                          QT += core gui widgets

                          I have it currently like this.

                          HEADERS= slider.h
                          SOURCES= main.cpp slider.cpp
                          
                          OTHER_FILES += \
                              readme.txt
                          QT += widgets
                          
                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          @JimmyMars

                          TEMPLATE = app
                          QT += core gui widgets
                          

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          JimmyMarsJ 1 Reply Last reply
                          4
                          • jsulmJ jsulm

                            @JimmyMars

                            TEMPLATE = app
                            QT += core gui widgets
                            
                            JimmyMarsJ Offline
                            JimmyMarsJ Offline
                            JimmyMars
                            wrote on last edited by
                            #15

                            @jsulm
                            That solved it.
                            Thanks for helping me out.

                            1 Reply Last reply
                            1
                            • Z Offline
                              Z Offline
                              ZiJia
                              wrote on last edited by
                              #16

                              To solve this problem, you need to follow the steps below.

                              1. In slider.cpp, change this expression emit m_slider->valueChanged(newValue) to emit valueChanged(newValue).

                              2. In slider.cpp, remove the implementation of valueChanged method. This means you need to remove the following part.

                              void Slider::valueChanged(int newValue){
                              m_slider->valueChanged(newValue);
                              }

                              Build it and you will find everything goes well.

                              Why?

                              When you declare valueChanged in slider.h with signals Macro as well as QObject Macro. It means Qt's moc compiler will help you deal with the implementation of valueChanged. So you shouldn't implement it. Unlike other C++ code, when you declare some method in .h file, you need to implement it in .cpp file. Actually, Qt follows this, but it has already made it done.

                              1 Reply Last reply
                              1

                              • Login

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