Moc_MyApp.cpp:94: multiple definition of `MyApp::ValueChanged(int) const' ---- first defined here MyApp.cpp
-
wrote on 26 Oct 2010, 04:45 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 = appSOURCES += main.cpp
MyApp.cppHEADERS +=
MyApp.h@
-
wrote on 26 Oct 2010, 04:48 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??
-
wrote on 26 Oct 2010, 06:24 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.
-
wrote on 26 Oct 2010, 06:49 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? -
wrote on 26 Oct 2010, 07:55 last edited by
Signals should not be implemented at all.
-
wrote on 26 Oct 2010, 08:20 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? -
wrote on 26 Oct 2010, 08:34 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?
-
wrote on 26 Oct 2010, 08:44 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/9