gpt4 book ai didi

c++ - Qt:更改 centralWidget 时崩溃

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

<分区>

我创建了自己的类,这里是ewindow.h:

#ifndef EWINDOW_H
#define EWINDOW_H
#include <QWidget>
#include <QString>
#include <mainwindow.h>

class MainWindow;

class EWindow
{
public:
EWindow(void (*callback)(EWindow*, MainWindow*), MainWindow *window, QString name, QString title);
QWidget *widget;
void resize(int width, int height);
void move(int x, int y);
void move();
void apply();
void append(QWidget *newWidget);
int* getSize();
~EWindow();

private:
int width, height, x, y;
QString name, title;
MainWindow *window;
};

#endif // EWINDOW_H

构造函数:

EWindow::EWindow(void (*callback)(EWindow*, MainWindow*), MainWindow *window, QString name, QString title) {
this->width = 0;
this->height = 0;
this->x = -1;
this->y = -1;
this->name = name;
this->title = title;
this->window = window;
this->widget = new QWidget();
(*callback)(this, window);
}

在回调中,我创建了一些小部件,如 QLabelQLineEdit。这是我的 apply 函数:

void EWindow::apply() {
window->setCentralWidget(this->widget);
window->setWindowTitle(this->title);
window->setFixedWidth(this->width);
window->setFixedHeight(this->height);
if (this->x == -1 || this->y == -1) this->move();
window->move(this->x, this->y);
}

但是!当我尝试为不同的 EWindows 调用应用函数 2 次时,我的程序崩溃了,没有任何错误。我认为这一行有错误:window->setCentralWidget(this->widget);。请帮忙,谢谢。

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