我按照以下教程:https://www.youtube.com/watch?v=1nzHSkY4K18
1 / test_opengl.pro
============================================== < / p>
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test_opengl
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
glwidget.cpp
HEADERS += mainwindow.h \
glwidget.h
FORMS += mainwindow.ui
=============================================== =
2 / glwidget.h
=============================================== =
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QGLWidget>
class GLWidget : public QGLWidget
{
Q_OBJECT
public:
explicit GLWidget(QWidget *parent = 0);
void initializeGL();
void paintGL();
void resizeGL(int w, int h);
};
#endif // GLWIDGET_H
=============================================== =============
3 / mainwindow.h
=============================================== =============
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
=============================================== =============
4 / glwidget.cpp
=============================================== =============
#include "glwidget.h"
GLWidget::GLWidget(QWidget *parent) :
QGLWidget(parent)
{
}
void GLWidget::initializeGL()
{
}
void GLWidget::paintGL()
{
}
void GLWidget::resizeGL(int w, int h)
{
}
=============================================== =============
5 / main.cpp中
=============================================== =============
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
=============================================== =============
6 / mainwindow.cpp
=============================================== =============
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
=============================================== =============
7 / mainwindow.ui
=============================================== =============
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>555</width>
<height>365</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Opengl</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="GLWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>&Quit</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>GLWidget</class>
<extends>QWidget</extends>
<header>glwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>383</x>
<y>342</y>
</hint>
<hint type="destinationlabel">
<x>390</x>
<y>230</y>
</hint>
</hints>
</connection>
</connections>
</ui>
=============================================== =============
调试时,我得到了:
下级停止是因为它收到了来自操作系统的信号。
信号名称:SIGSEGV
信号含义:分段错误
这个在反汇编程序上?
0x143d1fa6 ----------- 83 80 40 01 00 00 ff ------------- addl ----- $ 0xffffffff,0x140(%eax)< / p>
“非法访问内存”,“未初始化的指针”有什么问题?我该如何解决? 我使用Qt5.3.2,mingw,窗口7 32位。我的屏幕:http://postimg.org/image/pspg5e0g7/
答案 0 :(得分:0)
我认为我的驱动程序有问题,我尝试删除并设置Qt但旧版本(Qt 4.8.6)并且它已经运行。