我需要一种从窗口3转到窗口2的方法,请注意,从窗口2打开主窗口很容易,但是从3到2直到现在都不可能,这是我的代码,请让我知道是否可以解决,我们将不胜感激。
mainwindow.h
import plotly.express as px
iris = px.data.iris()
fig = px.scatter(iris, y="sepal_length")
fig.show()
window2.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "window2.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
window2 *W2;
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
window3.h
#ifndef WINDOW2_H
#define WINDOW2_H
#include <QWidget>
#include "window3.h"
namespace Ui {
class window2;
}
class window2 : public QWidget
{
Q_OBJECT
public:
explicit window2(QWidget *parent = nullptr);
window3 *W3;
~window2();
private slots:
void on_pushButton_clicked();
private:
Ui::window2 *ui;
};
#endif // WINDOW2_H
main.cpp
#ifndef WINDOW3_H
#define WINDOW3_H
#include <QWidget>
#include "windows2.h"
namespace Ui {
class window3;
}
class window3 : public QWidget
{
Q_OBJECT
public:
explicit window3(QWidget *parent = nullptr);
window2 *W2;
~window3();
private slots:
void on_pushButton_clicked();
private:
Ui::window3 *ui;
};
#endif // WINDOW3_H
mainwindow.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
window2.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "window2.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
W2 = new window2;
W2->show();
this->close();
}
window3.cpp
#include "window2.h"
#include "ui_window2.h"
window2::window2(QWidget *parent) :
QWidget(parent),
ui(new Ui::window2)
{
ui->setupUi(this);
}
window2::~window2()
{
delete ui;
}
void window2::on_pushButton_clicked()
{
W3 = new window3;
W3->show();
this->close();
}
这是我要犯的错误
#include "window3.h"
#include "ui_window3.h"
window3::window3(QWidget *parent) :
QWidget(parent),
ui(new Ui::window3)
{
ui->setupUi(this);
}
window3::~window3()
{
delete ui;
}
void window3::on_pushButton_clicked()
{
W2 = new window2;
W2->show();
this->close();
}