Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Moc_MyApp.cpp:94: multiple definition of `MyApp::ValueChanged(int) const' ---- first defined here MyApp.cpp

    General and Desktop
    3
    9
    8112
    Loading More Posts
    • 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.
    • B
      blackfacewa last edited by

      Hi,
      I want to test the slots and signals, so I define a class include some signals and slots function.

      but I got some link error after I build the project.

      So I don't know why in my moc_MyApp.cpp files include the all slots and signals function with the same name in MyApp.cpp ????
      Below is my app.pro files
      @
      #-------------------------------------------------

      Project created by QtCreator 2010-10-25T17:56:41

      #-------------------------------------------------

      QT += core

      QT -= gui

      TARGET = MyApp_02
      CONFIG += console
      CONFIG -= app_bundle
      TEMPLATE = app

      SOURCES += main.cpp
      MyApp.cpp

      HEADERS +=
      MyApp.h

      @

      1 Reply Last reply Reply Quote 0
      • B
        blackfacewa last edited by

        I can solved it if I remove the same name function from the moc_MyApp.cpp

        But I want to know why moc_MyApp.cpp create the same name function??

        1 Reply Last reply Reply Quote 0
        • F
          Franzk last edited by

          Signals are actually protected functions. Their implementation is done automatically by the moc to call any connected slots. If you want to write code that reacts to this signal, create a slot function and connect it to the signal.

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply Reply Quote 0
          • B
            blackfacewa last edited by

            to Franzk,
            Thanks to your answer!
            I see, I implements my signal and slot function in MyApp.cpp.

            But the same name signal and slot function created in moc_MyApp.cpp files when I compiler my projects.
            So why?

            1 Reply Last reply Reply Quote 0
            • D
              DenisKormalev last edited by

              Signals should not be implemented at all.

              1 Reply Last reply Reply Quote 0
              • B
                blackfacewa last edited by

                To Denis,
                I want to implement my signal function, so I must to implement it.
                Could you tell me why should not be implemented?

                1 Reply Last reply Reply Quote 0
                • F
                  Franzk last edited by

                  The reason you should not implement your signal is that it will be automatically implemented by the moc step. You will always run into errors whenever you implement a signal function yourself. Why do you want to write a custom implementation for it?

                  "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply Reply Quote 0
                  • D
                    DenisKormalev last edited by

                    Signal is not a function in its common meaning. Think about it like some marker that does not have any logic, just only name. If you want to add some logic at signal emitting you can make one more slot and connect it to this signal.

                    1 Reply Last reply Reply Quote 0
                    • F
                      Franzk last edited by

                      @Denis: That is probably the best way to go, but one kind of needs to know that it is actually a function when running into these types of issues.

                      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post