gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:23:25 26 4
gpt4 key购买 nike

我开始使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com