gpt4 book ai didi

c++ - Qt5以一种形式从另一种形式访问数据

转载 作者:行者123 更新时间:2023-11-28 04:40:50 24 4
gpt4 key购买 nike

如何从一种形式访问另一种形式的数据?

我有两种形式:主要形式:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "manualform.h"
#include "key.h"


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

Key cryptKey;

void MainWindow::on_autoKeyBtn_clicked()
{
cryptKey.createAuto();
QString output = cryptKey.toStrg();
ui->keyField->setText(output);
}

void MainWindow::on_manualKeyBtn_clicked()
{
ManualForm form;
form.setModal(true);
form.exec();
}

第二个:

#include "manualform.h"
#include "ui_manualform.h"
#include "key.h"

ManualForm::ManualForm(QWidget *parent) :
QDialog(parent),
ui(new Ui::ManualForm)
{
ui->setupUi(this);
}

ManualForm::~ManualForm()
{
delete ui;
}

Key key;

void ManualForm::on_confirmBtn_clicked()
{
this->close();
}

void ManualForm::on_resetBtn_clicked()
{

}

void ManualForm::on_checkBox00_toggled(bool checked)
{
Coord coord(0,0);
ui->checkBox09->setDisabled(checked);
ui->checkBox99->setDisabled(checked);
ui->checkBox90->setDisabled(checked);
key.add(coord);
}

假设 Key 对象将在 ManualForm 中创建并传输到 MainWindow 或 ManualForm 将获得对 MainWindow 的 cryptKey 的访问权。但这是一个我无法解决的问题。

最佳答案

您可以在堆上创建cryptKey 并使用signals and slots 将其传递给您的新表单。 .此外,您可以使用 QPointer以防万一您的其他表单删除了该对象。

您必须在 MainWindow 中定义一个信号,在 ManualForm 中定义一个槽,在 ManualForm 中最好将 cryptKey 定义为类对象。然后使用 emit 将对象发送到您的 ManualForm。您可能还必须使用 qRegisterMetaType 来注册对象。

关于c++ - Qt5以一种形式从另一种形式访问数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50199386/

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