View Full Version : Getting error “duplicate symbol: findNext” when there seems to be no duplication

17th August 2010, 01:52
Hi all,

I am just starting to use Qt (ok, I looked at it before for a short time, but now I'm back) and I'm trying to compile a simple program, but I'm getting duplicate symbol where there seems to be no duplicates. I'm actually following along in the book "C++ GUI Programming with Qt 4: Second Edition" by Blanchette & Summerfield. Starting on page 13, then talk about creating dialogs, so I created the files they said I should and now I'm getting this error. I have created a new project with the minimum number of lines to still get this error. To do so, I created a new gui application called TestMe, and removed the MainWindow class and header files from the project. I then added a FindDialog class to the project and defined them as such:

#include <QtGui/QApplication>
#include "finddialog.h"

int main(int argc, char *argv[])
QApplication a(argc, argv);

FindDialog *dialog = new FindDialog;

return a.exec();
-----------------------------------------------------end main.cpp---------------------------------


#include <QDialog>

class FindDialog : QDialog

FindDialog(QWidget *parent = 0);

void findNext(const QString &str, Qt::CaseSensitivity cs);


#endif // FINDDIALOG_H

--------------------------------------------end finddialog.h----------------------------------------

#include "finddialog.h"

FindDialog::FindDialog(QWidget *parent)
: QDialog(parent)

void FindDialog::findNext(const QString &str, Qt::CaseSensitivity cs)

--------------------------------------------end finddialog.cpp----------------------------------------

The error I'm getting from a fresh creation of this small project is:

--------------------------------------------compiler output----------------------------------------
Running build steps for project TestMe...
Configuration unchanged, skipping qmake step.
Starting: "/usr/bin/make" -w
make: Entering directory `/Users/bruce/Projects/Qt Projects/TestMe-build-desktop'
g++ -c -pipe -g -gdwarf-2 -arch i386 -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Qt4.6/mkspecs/macx-g++ -I../TestMe -I/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/usr/include/QtCore -I/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/usr/include/QtGui -I/usr/include -I. -I../TestMe -I. -F/Library/Frameworks -o finddialog.o ../TestMe/finddialog.cpp
../TestMe/finddialog.cpp:8: warning: unused parameter 'str'
../TestMe/finddialog.cpp:8: warning: unused parameter 'cs'
/Developer/Tools/Qt/moc -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Qt4.6/mkspecs/macx-g++ -I../TestMe -I/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/usr/include/QtCore -I/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/usr/include/QtGui -I/usr/include -I. -I../TestMe -I. -F/Library/Frameworks -D__APPLE__ -D__GNUC__ ../TestMe/finddialog.h -o moc_finddialog.cpp
g++ -c -pipe -g -gdwarf-2 -arch i386 -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Qt4.6/mkspecs/macx-g++ -I../TestMe -I/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/usr/include/QtCore -I/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/usr/include/QtGui -I/usr/include -I. -I../TestMe -I. -F/Library/Frameworks -o moc_finddialog.o moc_finddialog.cpp
g++ -headerpad_max_install_names -arch i386 -o TestMe.app/Contents/MacOS/TestMe main.o finddialog.o moc_finddialog.o -F/Library/Frameworks -L/Library/Frameworks -framework QtGui -framework QtCore
ld: duplicate symbol FindDialog::findNext(QString const&, Qt::CaseSensitivity) in moc_finddialog.o and finddialog.o
collect2: ld returned 1 exit status
make: *** [TestMe.app/Contents/MacOS/TestMe] Error 1
make: Leaving directory `/Users/bruce/Projects/Qt Projects/TestMe-build-desktop'
The process "/usr/bin/make" exited with code %2.
Error while building project TestMe (target: Desktop)
When executing build step 'Make'
--------------------------------------------end compiler output-----------------------------------

I have tried to figure this out, but don't seem to understand enough of what is going on with the moc process. If I comment out both the declaration and definition of the findNext() method, the compilation runs perfectly well. Can anybody help me with this? Seems like such a simple thing.


17th August 2010, 02:19
Signals are automatically implemented by the moc, you should not implement them yourself.

Just to be clear, you have to remove these lines from your .cpp.

void FindDialog::findNext(const QString &str, Qt::CaseSensitivity cs)