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. Moc_MyApp.cpp:94: multiple definition of `MyApp::ValueChanged(int) const' ---- first defined here MyApp.cpp

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

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 8.6k 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.
  • B Offline
    B Offline
    blackfacewa
    wrote on 26 Oct 2010, 04:45 last edited by
    #1

    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
    0
    • B Offline
      B Offline
      blackfacewa
      wrote on 26 Oct 2010, 04:48 last edited by
      #2

      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
      0
      • F Offline
        F Offline
        Franzk
        wrote on 26 Oct 2010, 06:24 last edited by
        #3

        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
        0
        • B Offline
          B Offline
          blackfacewa
          wrote on 26 Oct 2010, 06:49 last edited by
          #4

          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
          0
          • D Offline
            D Offline
            DenisKormalev
            wrote on 26 Oct 2010, 07:55 last edited by
            #5

            Signals should not be implemented at all.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              blackfacewa
              wrote on 26 Oct 2010, 08:20 last edited by
              #6

              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
              0
              • F Offline
                F Offline
                Franzk
                wrote on 26 Oct 2010, 08:34 last edited by
                #7

                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
                0
                • D Offline
                  D Offline
                  DenisKormalev
                  wrote on 26 Oct 2010, 08:44 last edited by
                  #8

                  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
                  0
                  • F Offline
                    F Offline
                    Franzk
                    wrote on 26 Oct 2010, 09:04 last edited by
                    #9

                    @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
                    0

                    1/9

                    26 Oct 2010, 04:45

                    • Login

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