c++ - Qt 创建者 - `multiple definition of qMain` 错误

标签 c++ qt

我开始使用 QT creator 制作 GUI 来做功课,但我遇到了这个错误,我无法找到它的原因,也无法理解它的含义。我想它两次看到我的主要功能,但我不知道为什么......请帮助我修复这个错误:

错误:

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

代码:

#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();
}

编辑:删除了长代码 - 不是错误的原因。检查有用的答案。

最佳答案

该链接错误的原因是因为代表 QT 创建者的行为不当。我在 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

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

关于c++ - Qt 创建者 - `multiple definition of qMain` 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10816655/

相关文章:

c++ - QGridLayout 没有按预期工作

c++ - 如何将输入焦点设置到 Qt 中显示的对话框?

c++ - float 到 SInt32

c++ - 处理按钮表 (WinAPI)

c++ - 删除 nullptr - 性能开销?

c++ - 如何获取 QGraphicsScene 项目中 QPolygonF 项目的当前角度?

windows - 隐藏终端上打印的所有 QT 应用程序警告?

由于父保护构造函数,C++ 无法实例化子类?

c++ - omp中的 "C6993: code analysis ignores OpenMP construct"是什么意思?

c++ - 为什么我的小部件不显示?