Qt创建者—“qMain”错误的多重定义。

时间:2022-05-05 21:27:46

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:

我开始为我的家庭作业使用QT创造者来制作GUI,但是我gt这个错误,我无法找到它的原因,我也不能理解它的意思。我想它看到了我的主要功能,但我不知道为什么……请帮助我解决这个错误:

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.

编辑:删除长的代码——而不是错误的原因。检查一下它是否有用。

4 个解决方案

#1


7  

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

造成链接错误的原因是由于笨拙的行为,或代表QT的创建者。我有一个项目名称。赞成

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.

谢谢你,我希望这篇文章将会对其他的QTcreator的新用户有用。

#2


5  

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

也许您的项目包含了另一个主要的源文件。文件复制的地方。检查“来源=”和main。cpp在你的。pro文件中。

#3


2  

You can only have one QApplication per program!

每个程序只能有一个QApplication !

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

检查您的类(控制器、StudentRepository、MainWindow),并确保它们没有声明QApplication。

#4


1  

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

它确实看到了qMain的两个定义,而不是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.

您可能已经接受了一个示例程序并通过添加代码来修改它。重新创建这些步骤,并查看它何时停止工作。在编写代码时,尽可能多地编写代码,以便在介绍完这些错误之后立即找到这些错误。

#1


7  

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

造成链接错误的原因是由于笨拙的行为,或代表QT的创建者。我有一个项目名称。赞成

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.

谢谢你,我希望这篇文章将会对其他的QTcreator的新用户有用。

#2


5  

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

也许您的项目包含了另一个主要的源文件。文件复制的地方。检查“来源=”和main。cpp在你的。pro文件中。

#3


2  

You can only have one QApplication per program!

每个程序只能有一个QApplication !

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

检查您的类(控制器、StudentRepository、MainWindow),并确保它们没有声明QApplication。

#4


1  

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

它确实看到了qMain的两个定义,而不是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.

您可能已经接受了一个示例程序并通过添加代码来修改它。重新创建这些步骤,并查看它何时停止工作。在编写代码时,尽可能多地编写代码,以便在介绍完这些错误之后立即找到这些错误。