Bogdan M.
Bogdan M.

Reputation: 2191

Qt creator - `multiple definition of qMain` error

I started to work for my homework using QT creator to make the GUI, but I gt this error and I can't manage to find the reason for it, nor can I understand what it means. I suppose it sees my main function twice but I do not know why... please assist me in fixing this error:

error:

Makefile.Debug:155: warning: overriding commands for target `debug/main.o'
    Makefile.Debug:142: warning: ignoring old commands for target `debug/main.o'
    debug/main.o: In function `Z5qMainiPPc':
    D:\c++\Labs\GUI_r/../../../info/qt/Desktop/Qt/4.8.1/mingw/include/QtGui/qwidget.h:494: multiple definition of `qMain(int, char**)'
    debug/main.o:D:\c++\Labs\GUI_r/main.cpp:7: first defined here
    collect2: ld returned 1 exit status

Code:

#include <QtGui/QApplication>
#include "mainwindow.h"
#include "controller.h"
#include "StudentRepository.h"

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

    StudentRepository *stre = new StudentRepository();
    Controller *c = new Controller(stre);
    MainWindow w(c);
    w.show();

    return a.exec();
}

edit: long code removed - not the reason for the error. Check the answere it is useful.

Upvotes: 2

Views: 10150

Answers (4)

Bogdan M.
Bogdan M.

Reputation: 2191

The reason for that linking error is because of awkawrd behaivior behalf QT creator. I had in the projectName.pro -

QT       +=    core gui

TARGET = GUI_r
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp \
    main.cpp \                   /////// Double call of main.cpp
    StudentRepository.cpp \
    controller.cpp

HEADERS  += mainwindow.h \
    controller.h \
    StudentRepository.h \
Student.h \
ui_mainwindow.h \        /////Double call of ui_mainwindow.h 
ui_mainwindow.h

FORMS    += mainwindow.ui

Thank you, i hope this post will be usefull to other new users of QTcreator.

Upvotes: 14

0xAX
0xAX

Reputation: 21837

Maybe your project contains another source file with a main. Somewhere files duplicated. Check "SOURCES =" and main.cpp in your .pro file.

Upvotes: 7

Agent_L
Agent_L

Reputation: 5420

It does see two definitions of qMain , not your main.

You have probably taken a sample program and modified it by adding your code. Recreate those steps and see when it stopped working. When writing a code, do a compilation as often as possible, to find such errors right after you've introduced them.

Upvotes: 1

karlphillip
karlphillip

Reputation: 93478

You can only have one QApplication per program!

Review your classes (Controller, StudentRepository, MainWindow) and make sure that they are not declaring QApplication as well.

Upvotes: 2

Related Questions