C++ Qt5以一种形式从另一种形式访问数据
如何从一种形式访问另一种形式的数据 我有两种表格: 主要形式:C++ Qt5以一种形式从另一种形式访问数据,c++,qt,data-transfer,C++,Qt,Data Transfer,如何从一种形式访问另一种形式的数据 我有两种表格: 主要形式: #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); }
#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);
}
假设密钥对象将在ManualForm中创建并传输到MainWindow,或者ManualForm将访问MainWindow的cryptKey。但这是一个我无法解决的问题。您可以在堆上创建加密密钥,并使用将其传递给新表单。此外,在其他窗体删除对象时,您可以使用此选项进行保护
您必须在MainWindow中定义一个信号,在ManualForm中定义一个插槽,最好将cryptKey定义为ManualForm中的类对象。然后使用“发射”将对象发送到手动表单。您可能还必须使用qRegisterMetaType来注册对象。可能会有任何问题,因为键对象属于myClass对象?您不应该将本地对象从MainWindow传递到ManualForm。如果您想修改Coord并从ManualForm发出它,解决方案是在MainWindow中创建一个槽。从堆中删除Key对象怎么样?C2059:使用delete cryptKey时出现语法错误:“delete”;删除密钥;在析构函数中应该可以。或者您将其分配为此父级。语法错误意味着您可能拼错了某些内容,