我需要你的帮助!
我的Qmainwindow中有8个dockwidget而没有一个centralwidget,当我尝试移动,浮动和取消包含3D视图的dockwidget时,程序崩溃并出现分段错误!
我会随时为您提供更多信息,非常感谢!
SUB_WIN_3D_VIEW.cpp
/* -----------------------
* ----------------------- */
#include "sub_win_3dview.h"
#include <QtWidgets/QAction>
#include <iostream>
#include <QDesktopServices>
SUB_WIN_3D_VIEW::SUB_WIN_3D_VIEW(Mainwindow const& p) : QDockWidget(),mainwindow_ins(p)
{
ui.setupUi(this);
this->setWindowTitle("3D view");
// Initiate the 3D scene
view.defaultFrameGraph()->setClearColor(QColor("#FFC0CBD9")); // light blue
widget = QWidget::createWindowContainer(&view);
view.renderSettings()->pickingSettings()->setPickMethod(Qt3DRender::QPickingSettings::TrianglePicking);
// Initiate the root entity (all the other entities of the scene should
// inherit it to be part of the 3D scene
rootEntity = new Qt3DCore::QEntity;
input = new Qt3DInput::QInputAspect;
view.setRootEntity(rootEntity);
view.registerAspect(input);
// Get the default camera entity from view
cameraEntity = view.camera();
// Set Z the be the vertical axis
cameraEntity->setUpVector(QVector3D(0, 0, 1));
// Initiate the camera controller
MyOrbitCameraController *camController = new MyOrbitCameraController(rootEntity);
camController->setCamera(cameraEntity);
camController->setLookSpeed(-300);
camController->setLinearSpeed(12);
// Initiate the light entity with its components below
lightEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DRender::QPointLight *lightPoint = new Qt3DRender::QPointLight(lightEntity);
lightPoint->setColor("white");
lightPoint->setIntensity(1);
Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
lightTransform->setTranslation(QVector3D(20, 20, 20));
lightEntity->addComponent(lightPoint);
lightEntity->addComponent(lightTransform);
// Initiate the modifier of the scene
modifier = new SceneModifier(rootEntity, cameraEntity);
modifier->pb_sl_reset();
view3d->widget->setMinimumSize(QSize(200, 100));
QSizePolicy view3d_siz(QSizePolicy::Expanding, QSizePolicy::Expanding);
widget->setSizePolicy(view3d_siz);
// Add the widget to a layout attached to the UI
ui.verticalLayout_2->addWidget(widget);
modifier->pb_sl_loadModel("simple");
connect(ui.Reload, SIGNAL(clicked(bool)),this, SLOT(reload_clicked()));
connect(ui.btn_CubeMiddle, SIGNAL(clicked(bool)),this, SLOT(cubeMiddle_clicked()));
connect(ui.btn_ObjUp, SIGNAL(clicked(bool)),this, SLOT(objUp_clicked()));
connect(ui.btn_ObjLeft, SIGNAL(clicked(bool)),this, SLOT(objLeft_clicked()));
connect(ui.btn_ObjRight, SIGNAL(clicked(bool)),this, SLOT(objRight_clicked()));
connect(ui.btn_ShowAxis, SIGNAL(clicked(bool)),this, SLOT(showAxis_clicked()));}
SUB_WIN_3D_VIEW::~SUB_WIN_3D_VIEW()
{
}
void SUB_WIN_3D_VIEW::reload_clicked()
{
// Reload's button simply load the same model again
modifier->pb_sl_loadModel("simple");
}
void SUB_WIN_3D_VIEW::cubeMiddle_clicked()
{
modifier->pb_sl_cameraMiddle();
}
void SUB_WIN_3D_VIEW::objUp_clicked()
{
modifier->pb_sl_cameraUp();
}
void SUB_WIN_3D_VIEW::objLeft_clicked()
{
modifier->pb_sl_cameraLeft();
}
void SUB_WIN_3D_VIEW::objRight_clicked()
{
modifier->pb_sl_cameraRight();
}
void SUB_WIN_3D_VIEW::showAxis_clicked()
{
modifier->pb_sl_enableRef(ui.btn_ShowAxis->isChecked());
}
#include "moc_sub_win_3dview.cpp"
错误:
在文件.... \ include / QtCore /../../ src / corelib / global / qglobal.h中,行 770:内存不足传递给C运行时函数的参数无效。 传递给C运行时函数的参数无效。 QWidget的::重绘: 检测到递归重绘
createDIB:CreateDIBSection失败。传递给C的参数无效 运行时功能。传递给C运行时函数的参数无效。 QWaitCondition:线程仍在等待时被破坏
答案 0 :(得分:0)
我通过修改qml代码解决了这个问题,
file.h
QQuickWidget *m_quickWidget_gauge_2;
QObject *object_gauge_2 ;
QQuickWidget *m_quickWidget_gauge_3;
QObject *object_gauge_3 ;
QQuickWidget *m_quickWidget_gauge_4;
QObject *object_gauge_4 ;
file.cpp
//QQuickWidget : actuator number 1
m_quickWidget_gauge_1 = new QQuickWidget(this) ;
m_quickWidget_gauge_1->setSource(QUrl("qrc:/Resources/res/gauge.qml"));
m_quickWidget_gauge_1->setResizeMode(QQuickWidget::SizeRootObjectToView);
m_quickWidget_gauge_1->setMinimumHeight(30);
m_quickWidget_gauge_1->setMinimumWidth(150);
m_quickWidget_gauge_1->setAttribute(Qt::WA_AlwaysStackOnTop);
m_quickWidget_gauge_1->setClearColor(Qt::transparent);
ui.horizontalLayout_al_1->addWidget(m_quickWidget_gauge_1, 1, Qt::AlignTop);
//QQuickWidget : actuator number 2
m_quickWidget_gauge_2 = new QQuickWidget(this) ;
m_quickWidget_gauge_2->setSource(QUrl("qrc:/Resources/res/gauge.qml"));
m_quickWidget_gauge_2->setResizeMode(QQuickWidget::SizeRootObjectToView);
m_quickWidget_gauge_2->setMinimumHeight(30);
m_quickWidget_gauge_2->setMinimumWidth(150);
m_quickWidget_gauge_2->setAttribute(Qt::WA_AlwaysStackOnTop);
m_quickWidget_gauge_2->setClearColor(Qt::transparent);
ui.horizontalLayout_al_2->addWidget(m_quickWidget_gauge_2, 1, Qt::AlignTop);
//QQuickWidget : actuator number 3
[....]
我进行了这些更改,并且可以正常工作!
file.h
QQuickView *m_qmlview_gauge_1;
QQuickView *m_qmlview_gauge_2;
QQuickView *m_qmlview_gauge_3;
file.cpp
m_qmlview_gauge_1 = new QQuickView(QUrl("qrc:/Resources/res/qml/actuator_gauge.qml"));
m_qmlview_gauge_1->setColor(QColor(Qt::white));
QWidget *container = QWidget::createWindowContainer(m_qmlview_gauge_1);
container->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Expanding);
ui.verticalLayout_11->addWidget(container);
m_qmlview_gauge_2 = new QQuickView(QUrl("qrc:/Resources/res/qml/actuator_gauge.qml"));
m_qmlview_gauge_2->setColor(QColor(Qt::white));
QWidget *container_1 = QWidget::createWindowContainer(m_qmlview_gauge_2);
container_1->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Expanding);
ui.verticalLayout_12->addWidget(container_1);
m_qmlview_gauge_3 = new QQuickView(QUrl("qrc:/Resources/res/qml/actuator_gauge.qml"));
m_qmlview_gauge_3->setColor(QColor(Qt::white));
QWidget *container_2 = QWidget::createWindowContainer(m_qmlview_gauge_3);
container_2->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Expanding);
ui.verticalLayout_13->addWidget(container_2);
我仍然不明白为什么旧代码会导致此崩溃,它在!!之前效果很好!