QT扩展主窗口到其他类或不同的方式
QT extend MainWindow to other class or diffrent way
我有一个class printrectangle
class PrintRectangle : public QWidget
{
Q_OBJECT
public:
explicit PrintRectangle(QWidget *parent = 0);
private:
void resetClickedIndex();
void updateIndexFromPoint( const QPoint& point);
public:
int mXIndex;
int mYIndex;
QVector<QPoint> points;
bool clicked[5][5] = {};
teacher tech;
perceptron p[5][5];
double techconst = 0.1;
signals:
public slots:
protected:
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *eventPress);
};
和MainWindow
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_learn_clicked();
void on_classify_clicked();
private:
Ui::MainWindow *ui;
};
当我点击按钮时,我调用on_learn_clicked()
函数。我想将clicked[5][5]
数组转换为on_learn_clicked
,因为当用户单击按钮时,我将此数组发送给其他对象。如何做到这一点?
目前还不清楚MainWindow和PrintRectangle小部件之间究竟是什么关系。我想按钮信号和PrintRectangle插槽是在MainWindow实现的某个地方连接的。
解决这个问题的一种方法是使用QSignalMapper,如@Noidea所述。
另一种方法是在连接时使用lambda作为插槽。通过这种方式,您可以捕获范围内的发送方/接收方或其他对象,并使用它们的成员。
您可以在新信号槽语法
中找到有关连接语法的一些信息但是基本上你可以这样写:
connect(button, &QPushButton::clicked, this, [this, printRectangle]()
{
// do smth with clicked[5][5] from printRectangle or just
// retrieve it and call another method like:
// this->processClicked(printRectangle->clicked);
// or pass it to another object
}
这样,您可以将on_classify_clicked slot修改为带有bool[5][5]参数的常规方法来执行处理。
相关文章:
- 我如何在一个 if 语句中声明所有数字我尝试通过其他方式声明所有数字,如果一个接一个,但似乎代码有逻辑错误
- 我如何使用“ op parallel”或其他方式并行循环
- 无法以正确的方式执行其他程序
- 类定义中定义的成员函数的编译方式是否与C++中其他位置定义的成员函数不同
- 实时在语言之间流水线传输或以其他方式传输数据
- 如何根据其ARITY(或编译时已知的其他信息)以不同的方式调用函数对象
- 如何通过Visual Studio COM包装(或其他方式)在C#中使用C++属性联合
- visual在源代码中是否有预定义的#define或其他方式来了解它是为C++/CX Windows运行时编译的
- 在 VS 中,以编程方式获取链接器>其他库目录属性,或获取宏值
- C++ 如何通过可选的typedef,使用SFINAE或其他方式选择类
- 在C++中,函数在main()中更改变量的任何其他方式
- C++如何用模板指定或其他方式实现
- 用于循环的C++没有以其他方式输出
- 编译器看不到函数,可以看到所有其他以相同方式使用的函数
- 比如果其他更好的方式..用于线性插值
- 与其他字符相比,c++/Arduino 处理“?”的方式是否不同
- 无法在 Windows 中以编程方式从其他用户帐户读取文件(C++)
- 如何防止以 A 类以外的任何其他方式创建 B 类的对象
- 使用其他库分发应用程序的"正确方式"
- 从Java调用WinMain:可能吗?任何其他方式