RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1355330
Accepted
timob256
timob256
Asked:2022-04-29 22:43:42 +0000 UTC2022-04-29 22:43:42 +0000 UTC 2022-04-29 22:43:42 +0000 UTC

我不明白为什么 qopenglwidget 不起作用

  • 772

我将 qopenglwidget 推到主小部件中,但由于某种原因它没有启动。

我也不能使用 qt 3D 和 Quick 3D

这是代码

对话窗口.h

#ifndef DIALOGOKNO_H
#define DIALOGOKNO_H

#include <QMainWindow>
#include <QFile>
#include <QPushButton>
#include <QLabel>
#include <QSize>

#include <QApplication>
#include <QDesktopWidget>
#include <QRect>
#include <QDebug>
#include <QLineEdit>
#include <QGridLayout>
#include <QSpacerItem>
#include <QObject>
#include "qopenglwidget.h"


class DialogOkno : public QWidget
{
    Q_OBJECT

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

protected:
    QFile* file;         // загрузить файл
    QGridLayout* gl_layaout[4];
    QPushButton* b_load; // кнопка для выбора и загрузки файла
    QLabel* l_label[3];
    QLineEdit* le_edit[7];
    QSpacerItem* si_spacer[4];
    QOpenGLWidget *openGLWidget;

    //опен гл
    void initializeGL();
    void paintGL();
    void resizeGL(int width, int height);
};

#endif // DIALOGOKNO_H

对话窗口.cpp

#include "dialogokno.h"

DialogOkno::DialogOkno(QWidget *parent)
    : QWidget(parent)
{
    // обявл элементы
    gl_layaout[0] = new QGridLayout(parent);
    gl_layaout[1] = new QGridLayout(parent);
    gl_layaout[2] = new QGridLayout(parent);

    gl_layaout[3] = new QGridLayout(parent);

    openGLWidget = new QOpenGLWidget(parent);

    l_label[0] = new QLabel(parent);
    l_label[1] = new QLabel(parent);
    l_label[2] = new QLabel(parent);

    le_edit[0] = new QLineEdit(parent);
    le_edit[1] = new QLineEdit(parent);
    le_edit[2] = new QLineEdit(parent);
    le_edit[3] = new QLineEdit(parent);
    le_edit[4] = new QLineEdit(parent);
    le_edit[5] = new QLineEdit(parent);
    le_edit[6] = new QLineEdit(parent);

    // настройки элеметов (стилизация)

    // заполнение элементов
    l_label[0]->setText("hla_global");
    l_label[1]->setText("hla_local");
    l_label[2]->setText("logger");

    le_edit[0]->setText("server_ip_global");
    le_edit[1]->setText("server_port_global");

    le_edit[2]->setText("server_port_local");
    le_edit[3]->setText("server_port_local");

    le_edit[4]->setText("log");
    le_edit[5]->setText("log_period_ms");
    le_edit[6]->setText("log_size_in_mb");

    //разложение элементов по группам

    gl_layaout[0]->addWidget(l_label[0], 0, 0, 1, 1);
    gl_layaout[0]->addWidget(le_edit[0], 1, 0, 1, 1);
    gl_layaout[0]->addWidget(le_edit[1], 2, 0, 1, 1);

    gl_layaout[1]->addWidget(l_label[1], 0, 0, 1, 1);
    gl_layaout[1]->addWidget(le_edit[2], 1, 0, 1, 1);
    gl_layaout[1]->addWidget(le_edit[3], 2, 0, 1, 1);

    gl_layaout[2]->addWidget(l_label[2], 0, 0, 1, 1);
    gl_layaout[2]->addWidget(le_edit[4], 1, 0, 1, 1);
    gl_layaout[2]->addWidget(le_edit[5], 2, 0, 1, 1);
    gl_layaout[2]->addWidget(le_edit[6], 3, 0, 1, 1);


    gl_layaout[3]->addLayout(gl_layaout[0], 0, 0, 1, 1);

    si_spacer[0] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    gl_layaout[3]->addItem(si_spacer[0], 0, 1, 1, 1);

    gl_layaout[3]->addLayout(gl_layaout[1], 0, 2, 1, 1);
    si_spacer[1] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    gl_layaout[3]->addItem(si_spacer[1], 0, 3, 1, 1);
    si_spacer[2] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
    gl_layaout[3]->addItem(si_spacer[2],1, 0, 1, 1);
    gl_layaout[3]->addLayout(gl_layaout[2], 2, 0, 1, 1);
    si_spacer[3] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding);
    gl_layaout[3]->addItem(si_spacer[3],3,0);
    gl_layaout[3]->addWidget(openGLWidget, 1, 1, 3, 3);

    this->setLayout(gl_layaout[3]);
}

DialogOkno::~DialogOkno()
{

}

void QOpenGLWidget::initializeGL()
{
    glClearColor(1.0, 1.0, 1.0, 0.0);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}

void QOpenGLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glColor3f(0.0, 0.0, 0.0);
    glBegin(GL_QUADS);
    glVertex3f (0.51, 0.51, 0.51);
    glVertex3f (-0.51, 0.51, 0.51);
    glVertex3f (-0.51, -0.51, 0.51);
    glVertex3f (0.51, -0.51, 0.51);
    glEnd();

 }

void QOpenGLWidget::resizeGL(int width, int height)
{
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
}

主文件

#include "dialogokno.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    DialogOkno w;

    QDesktopWidget desktop;
    QRect rect = desktop.availableGeometry(desktop.primaryScreen()); // прямоугольник с размерами экрана
    QPoint center = rect.center(); //координаты центра экрана
 
    qDebug() << "rect.x()/2 " <<rect.y()/2  << "rect.y()/2" << rect.y()/2;
    qDebug() << "center.x()/2 " <<center.y()  << "center.y()/2" << center.y();

    w.resize(center.x(), center.y());
    w.setWindowTitle("программа");
    w.show();

    return a.exec();
}

dialog_window_qmake.pro

#-------------------------------------------------
#
# Project created by QtCreator 2021-11-24T16:28:03
#
#-------------------------------------------------

QT       += core gui opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = dialog_okno_qmake
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
        main.cpp \
        dialogokno.cpp

HEADERS += \
        dialogokno.h


INCLUDEPATH += $$PWD/glfw_bin/include/GLFW/ \ # добавляем для удобства чтоб напрямую писать
               $$PWD/glew_bin/include/GL/  \  # только название заголовчного файла без полного пути
               $$PWD/stb_image/

HEADERS += \
    glfw_bin/include/GLFW/glfw3.h \
    glfw_bin/include/GLFW/glfw3native.h \
    glew_bin/include/GL/glew.h \

# --- linux ---

unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/x86_64-linux-gnu/ -lOpenGL

INCLUDEPATH += $$PWD/../../../../usr/include/GL
DEPENDPATH += $$PWD/../../../../usr/include/GL

unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/x86_64-linux-gnu/ -lGLEW

INCLUDEPATH += $$PWD/../../../../usr/include/GL
DEPENDPATH += $$PWD/../../../../usr/include/GL

unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/x86_64-linux-gnu/ -lglut

INCLUDEPATH += $$PWD/../../../../usr/include/GL
DEPENDPATH += $$PWD/../../../../usr/include/GL

unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/x86_64-linux-gnu/ -lGLU

INCLUDEPATH += $$PWD/../../../../usr/include/GL
DEPENDPATH += $$PWD/../../../../usr/include/GL

截图_20211129_165752.png

输出:

Запускается /home/dima/dima_project/dialog_okno_qmake/dialog_okno_qmake...
rect.x()/2  0 rect.y()/2 0
center.x()/2  515 center.y()/2 515
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
QOpenGLContext::makeCurrent() called with non-opengl surface 0x59b7a92e99a0
composeAndFlush: makeCurrent() failed
/home/dima/dima_project/dialog_okno_qmake/dialog_okno_qmake завершился с кодом 0
qt
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    timob256
    2022-04-30T21:26:34Z2022-04-30T21:26:34Z

    一般来说,这是一个在 Astra Linux 中跳出来的错误。

    这是答案(https://wiki.astralinux.ru/pages/viewpage.action?pageId=43614493)

    我使用了第一个选项

    #include "dialogokno.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QApplication::setAttribute(Qt::AA_ForceRasterWidgets, false);
        DialogOkno w;
    
        QDesktopWidget desktop;
        QRect rect = desktop.availableGeometry(desktop.primaryScreen()); // прямоугольник с размерами экрана
        QPoint center = rect.center(); //координаты центра экрана
    
        qDebug() << "rect.x()/2 " <<rect.y()/2  << "rect.y()/2" << rect.y()/2;
        qDebug() << "center.x()/2 " <<center.y()  << "center.y()/2" << center.y();
    
        w.resize(center.x(), center.y());
        w.setWindowTitle("программа");
        w.show();
    
        return a.exec();
    }
    

    添加了一行

           QApplication::setAttribute(Qt::AA_ForceRasterWidgets, false);
    

    一切正常:3

    • 0

相关问题

  • 在 Windows 7 上将文件连接到 Qt 项目时出现问题

  • QGraphicsView - Qt5 - MouseMoveEvent 没有触发?

  • 如何在背景中添加屏幕保护程序

  • 如何更改包含的 .ttf 字体的大小

  • QString("%1").arg(number + 1) 以 %03d 格式打印数字

  • QT Creator,信号和插槽 [关闭]

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    表格填充不起作用

    • 2 个回答
  • Marko Smith

    提示 50/50,有两个,其中一个是正确的

    • 1 个回答
  • Marko Smith

    在 PyQt5 中停止进程

    • 1 个回答
  • Marko Smith

    我的脚本不工作

    • 1 个回答
  • Marko Smith

    在文本文件中写入和读取列表

    • 2 个回答
  • Marko Smith

    如何像屏幕截图中那样并排排列这些块?

    • 1 个回答
  • Marko Smith

    确定文本文件中每一行的字符数

    • 2 个回答
  • Marko Smith

    将接口对象传递给 JAVA 构造函数

    • 1 个回答
  • Marko Smith

    正确更新数据库中的数据

    • 1 个回答
  • Marko Smith

    Python解析不是css

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5