[solved] Getting error "duplicate symbol: findNext" when there seems to be no duplication



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

    @
    -----------------main.cpp----------------------
    #include <QtGui/QApplication>
    #include "finddialog.h"

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

    FindDialog *dialog = new FindDialog;
    dialog->show();
    
    return a.exec&#40;&#41;;
    

    }
    --------------end main.cpp---------------------

    --------------finddialog.h-----------------------
    #ifndef FINDDIALOG_H
    #define FINDDIALOG_H

    #include <QDialog>

    class FindDialog : QDialog
    {
    Q_OBJECT

    public:
    FindDialog(QWidget *parent = 0);

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

    };

    #endif // FINDDIALOG_H

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

    -----------finddialog.cpp------------------------
    #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:

    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&#41; 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'

    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.

    Thanks...

    [edit: formatting fixed / Denis Kormalev]



  • Oh, I didn't say that I'm on MacOS 10.6.4 running Qt 4.7 using QtCreator 2.0.0. I'm up to the latest on all three. Can't be my install, I'm assuming.



  • In your header file, you have findNext() defined in the signals section. This means that MOC will generate a function findNext() as well, which causes the duplicate symbol. Move the findNext function to "(public|protected|private)(slots)?:"

    The hint is given by: duplicate symbol FindDialog::findNext(QString const&, Qt::CaseSensitivity) in moc_finddialog.o and finddialog.o

    So you would end up with for example:
    @public slots:
    void findNext(const QString &, Qt::CaseSensitivity); @

    instead of

    @signals:
    void findNext(const QString &, Qt::CaseSensitivity); @



  • Thank you very much. Such a simple thing. I knew it had to be a moc thing I wasn't understanding/remembering. Thanks a lot for helping. I'm on my way again. Whooppee!!! :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.