QWidget:必须在QWidget之前构造一个QApplication,错误?

时间:2015-11-07 00:35:10

标签: c++ visual-studio qt opengl

我正在使用QT和OpenGL在Visual Studio中完成一项任务。

我在配置QT并运行它时遇到了问题。我修复了很多错误,现在它没有向我显示任何错误,但是当我编译它时,它几乎一直到最后,然后停止。以下是VS显示的日志:

'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Cored.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\lpk.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\usp10.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\ws2_32.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\nsi.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\mpr.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msvcp120d.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msvcr120d.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Widgetsd.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Guid.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5OpenGL.dll'. Module was built without symbols.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Widgets.dll'. Module was built without symbols.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Gui.dll'. Module was built without symbols.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\bin\Qt5Core.dll'. Module was built without symbols.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msvcp120.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msvcr120.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\msctf.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\cryptbase.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Qt\5.5\msvc2013_64\plugins\platforms\qwindowsd.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\winmm.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\uxtheme.dll'. Symbols loaded.
'testClasa2.exe' (Win32): Loaded 'C:\Windows\System32\dwmapi.dll'. Symbols loaded.
QWidget: Must construct a QApplication before a QWidget
The program '[5200] testClasa2.exe' has exited with code 1 (0x1).

在日志的最后,你可以看到它说: QWidget:必须在QWidget之前构建一个QApplication 我真的不知道这意味着什么:(

以下是课程:

main.cpp中:

#include "testclasa2.h"
#include <QtWidgets/QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    testClasa2 w;
    w.show();
    return a.exec();
}

testClass2.cpp:

#include "testclasa2.h"

testClasa2::testClasa2(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
}

testClasa2::~testClasa2()
{

}

testClass2.h:

#ifndef TESTCLASA2_H
#define TESTCLASA2_H

#include <QtWidgets/QMainWindow>
#include <QApplication>
#include "ui_testclasa2.h"

class testClasa2 : public QMainWindow
{
    Q_OBJECT

public:
    testClasa2(QWidget *parent = 0);
    ~testClasa2();

private:
    Ui::testClasa2Class ui;
};

#endif // TESTCLASA2_H

taliWidget.cpp:

#include "taliWidget.h"

//#include "taliWidget.h"
#include <GL/glut.h>
taliWidget::taliWidget(QWidget *parent)
: QGLWidget(parent)
{
}

//taliWidget::~taliWidget()
//{
//}
void initiliazeGL(){

}
//void paintGL(){
//
//}
//void resizeGL(int w, int h){
//
//}

taliWidget.h:

#ifndef TALIWIDGET_H
#define TALIWIDGET_H

#include <QtOpenGL\qglwidget>
class taliWidget :
    public QGLWidget
{
    Q_OBJECT
public:

    explicit taliWidget(QWidget *parent = 0);
    //~taliWidget();

    void initiliazeGL();
    /*void paintGL();
    void resizeGL(int w, int h);*/
};

#endif // GLWIDGET_H

0 个答案:

没有答案