-1

I have 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);
};

and 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;
};

When I click button I call to on_learn_clicked() function. I would like to transfer clicked[5][5] array into on_learn_clicked becasue I send this array to other object when user click button. How to do this?

lukassz
  • 3,135
  • 7
  • 32
  • 72
  • see this post on how to add parameter to a slot: http://stackoverflow.com/questions/5153157/passing-an-argument-to-a-slot – Noidea Nov 18 '16 at 16:26

1 Answers1

0

It is not clear what is exactly the relation between MainWindow and the PrintRectangle widget. I suppose the button signal and PrintRectangle slot are connected somewhere in the MainWindow implementation.

One way to solve the problem would be to use to use the QSignalMapper as @Noidea stated.

Another way would be to use a lambda as a slot when connecting. This way you could capture the sender/receiver or other objects in scope and use their members.

You can find some information about the connect syntax in New Signal Slot Syntax

But basically you could write something like:

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
}

This way you could modify your on_classify_clicked slot to a regular method with bool[5][5] argument to do the processing.

Dusteh
  • 1,496
  • 16
  • 21