如何在qt中从另一个类调用函数
how to call function from another class in qt?
这是我的代码:
主窗口.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "secd.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionSettings_triggered()
{
secD secdialog;
secdialog.setModal(true);
secdialog.exec();
}
void function1() //this function I need to call from secd.cpp
{
//do something
}
secd.cpp:
#include "secd.h"
#include "ui_secd.h"
#include <QMessageBox>
#include "mainwindow.h"
secD::secD(QWidget *parent) :
QDialog(parent),
ui(new Ui::secD)
{
ui->setupUi(this);
}
secD::~secD()
{
delete ui;
}
void secD::on_buttonBox_accepted()
{
QMessageBox msgBox;
msgBox.setWindowTitle("About");
msgBox.exec();
function1(); //how to call this function?
}
所以我需要从主窗口.cpp中的secd.cpp函数1((调用我该怎么做?也许有连接、信号和插槽?但我不懂那些文件。
函数的原型应该直接或在头文件中声明:
#include "secd.h"
#include "ui_secd.h"
#include <QMessageBox>
#include "mainwindow.h"
void function1(); // <---------------------------
secD::secD(QWidget *parent) :
QDialog(parent),
ui(new Ui::secD)
{
ui->setupUi(this);
}
secD::~secD()
{
delete ui;
}
void secD::on_buttonBox_accepted()
{
QMessageBox msgBox;
msgBox.setWindowTitle("About");
msgBox.exec();
function1(); //how to call this function?
}
相关文章:
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 在另一个线程中调用luaL_error会引发qWarning
- 如何在qt中从另一个类调用函数
- 检查哪个对象调用了另一个对象的对象方法
- 如何确定哪个标头调用 c++ 中的另一个标头
- 在另一个函数 (c++) 中调用变量
- 使用另一个程序调用正在运行的 C++ 程序中的函数
- 如何从另一个标头 c++ 调用函数
- 为什么从另一个构造函数内部调用C++构造函数不修改类变量?
- 将类成员函数作为线程调用到另一个类成员函数时发出警告消息
- 使用指向成员函数的指针在另一个类中调用类构造函数
- 从另一个标头中的标头调用静态方法
- 无法"this"指针传递到另一个类并在 CPP 中调用该类的任何方法
- C++ |DLL / EXE - 如何从导出的类调用另一个类方法?
- 在模板化的 Rcpp 函数中调用另一个 cpp 函数
- 在销毁期间从另一个线程调用对象上调用方法是否未定义行为?
- C++ 如何根据作为输入传递的参数调用一个构造函数或另一个构造函数?
- 编译器在C++中调用另一个函数时,在参数中查找已删除的构造函数
- 当另一个调用 lambda 使用默认捕获时,lambda 的闭包可能会被破坏吗?
- 在C++中嵌入Python:在Python脚本中导入模块在一个函数调用过程中有效,但在另一个调用过程中无效