user466534
user466534

Reputation:

Problems on Qt on NetBeans

After having solved a Qt configured problem on my system, I have now installed NetBeans and everything is OK. It is just that I have the following problem. Here is the code:

#include <QtGui/QApplication>
#include <QDir>
#include <QFileInfo>
#include <QtDebug>
int main(int argc, char **argv) {
    foreach(QFileInfo  drive,QDir::drives()){
        qDebug()<<"Drive: "<<drive.absolutePath();
        QDir dir=drive.dir();
        dir.setFilter(QDir::Dirs);
        foreach(QFileInfo rootDirs,dir.entryInfoList())

        qDebug()<< " "<<rootDirs.fileName();
    }
    return 0;
   // return app.exec();
}

and errors are

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/david/NetBeansProjects/QtApplication_1'
/usr/bin/qmake VPATH=. -o qttmp-Debug.mk nbproject/qt-Debug.pro
mv -f qttmp-Debug.mk nbproject/qt-Debug.mk
/usr/bin/make -f nbproject/qt-Debug.mk dist/Debug/GNU-Linux-x86/QtApplication_1
make[2]: Entering directory `/home/david/NetBeansProjects/QtApplication_1'
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -Inbproject -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -Inbproject -I. -o build/Debug/GNU-Linux-x86/Qt1.o Qt1.cpp
Qt1.cpp:7: warning: unused parameter ‘argc’
Qt1.cpp:7: warning: unused parameter ‘argv’
g++  -o dist/Debug/GNU-Linux-x86/QtApplication_1 build/Debug/GNU-Linux-x86/Qt1.o build/Debug/GNU-Linux-x86/main.o    -L/usr/lib -lQtGui -lQtCore -lpthread
build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/david/NetBeansProjects/QtApplication_1/main.cpp:10: multiple definition of `main'
build/Debug/GNU-Linux-x86/Qt1.o:/home/david/NetBeansProjects/QtApplication_1/Qt1.cpp:7: first defined here
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/QtApplication_1] Error 1
make[2]: Leaving directory `/home/david/NetBeansProjects/QtApplication_1'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/david/NetBeansProjects/QtApplication_1'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)

How can I fix this problem?

Upvotes: 1

Views: 771

Answers (1)

Arnold Spence
Arnold Spence

Reputation: 22272

According to that output, you are compiling two source files Qt1.cpp and main.cpp, both of which define the function main(). You need to remove one of those two files from your project or remove the definition of main() from one of them.

As an added step to get rid of the warning about unused parameters in main(), change it to

main(int /*argc*/, char **/*argv*/)

until you need to use those arguments.

Upvotes: 2

Related Questions