Important: Please read the Qt Code of Conduct -

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

  • 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 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

    HEADERS +=


  • 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??

  • 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.

  • 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?

  • Signals should not be implemented at all.

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

  • 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?

  • 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.

  • @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.

Log in to reply