如何在QT的其他小部件中调用创建的小部件对象
How to call created widget object in other widgets in QT
在我的应用程序中,我有三个小部件,我在main()
函数中为所有小部件创建了对象,但我不知道如何在其他小部件中调用创建的对象,请指导我,我这样创建对象:
#include <QtGui/QApplication>
#include "widget.h"
#include "one.h"
#include "two.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget *w = new Widget();
One *one = new One();
Two *two = new Two();
w->show();
return a.exec();
}
创建的对象如何调用其他小部件?
您不应该'调用'它们,而是通过Qt信号槽机制连接它们:
class One : public QObject {... boilerplate omitted
public slots:
void slotWithVoid(){ emit slotWithInt(1); }
signals:
void signalWithInt(int); // filled in by Qt moc
};
// note: give your widgets an owner
auto *w = new QButton(&app);
auto *one = new One(&app);
auto *two = new Two(&app);
connect(w, &QButton::click,
one, &One::slotWithVoid);
connect(one, &One::signalWithInt,
two, &Two::slotWithInt);
现在当一些事情发生(例如按钮点击),Qt事件系统将照顾你的对象被调用在正确的顺序,从正确的线程,安全等…
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 最小硬币更换问题(自上而下方法)
- 什么时候调用组成单元对象的析构函数
- 调用一个小函数两次(例如在if条件和主体中)比将结果存储在局部变量中更可取
- 当对话框中的任何小部件发出信号时,是否可以调用插槽
- 从 Qt 小部件应用程序调用 pyqt widget
- 如何每秒调用更新Qt小部件的函数
- malloc调用在一个看似很小的请求后失败
- 如何最小化调用列表构造函数(复制构造函数)的次数?
- 最小化函数选择和函数调用开销
- C++ 创建小部件数组
- 为什么排序调用比较函数的频率低于线性最小搜索算法
- 调用父小部件函数
- WinInet InternetReadFile返回0x8007007a(传递给系统调用的数据区域太小)
- Qt从其他小部件调用QMainWindow方法的最佳方式
- 如何在QT的其他小部件中调用创建的小部件对象
- QT小部件插槽调用没有被单独的线程信号激活
- 如何以最小的延迟依次调用两个函数
- 何时在小部件上调用update()
- 从结构体内部调用成员函数指针所指向的函数