A
A
Arkasar2014-04-23 21:14:20
Qt
Arkasar, 2014-04-23 21:14:20

Qt can't pass array between forms. It looks like the signal is not reaching the slot. What could be the problem?

I work with arrays, I need to display data on a graph in a different form.
mainwindow.h

#include <form.h>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);

    /......../

    ~MainWindow();


private slots:
    void on_pushButtonGen_clicked();

    void on_pushButtonGO_clicked();

    void on_pushButtonShowGraph_clicked();
signals:
    void sendData(int PopulationSum, double fitnesMean);

private:
    Ui::MainWindow *ui;
    Form *form;
};

#endif // MAINWINDOW_H

the sendData signal will be sent to the on_pushButtonGen_clicked()
function The header file of the form where the data from the main one will be sent.
form.h
#ifndef FORM_H
#define FORM_H

#include <QWidget>

namespace Ui {
class Form;
}
class Form : public QWidget
{
    Q_OBJECT

public:
    explicit Form(QWidget *parent = 0);
    ~Form();
private:
    Ui::Form *ui;
/......../

public slots:
    void recieveData(int _PopulationSum, double _fitnesMean);
};
#endif // FORM_H

The sendData signal goes to the recieveData slot
This is how I defined this slot in form.cpp
void Form::recieveData(int _PopulationSum, double _fitnesMean)
{

    points <<QPointF(_PopulationSum,_fitnesMean);
    curve->setSamples( points ); 
     curve->attach( ui->Qwt_Widget ); 
     ui->lineEdit->setText("I WORK");  ///проверяет, работает ли функция...не работает..
}

Well, actually
mainwindow.cpp itself
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <form.h>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    form = new Form();
    connect(ui->pushButtonShowGraph, SIGNAL(clicked()), form, SLOT(show())); // 
    connect(ui->pushButtonGen, SIGNAL(clicked()), this, SLOT(on_pushButtonGen_clicked())); 
    connect(this, SIGNAL(sendData(int PopulationSum, double fitnesMean)), form, 
SLOT(recieveData(int _PopulationSum, double _fitnesMean))); 

}

MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::on_pushButtonGen_clicked()
{
    /....код генерирующий и обрабатывающий массивы....\
    emit sendData(PopulationSum,PBest->fitnessMean); //не могу понять, почему не доходит.
}

What could be the problem? Tell me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2014-04-23
@Arkasar

And when you start the application, the console does not display notifications about the impossibility of creating a connection or something like that?
in connect it is not necessary to write the name of the variables. Those. connect(this, SIGNAL( sendData
(int, double)), form, SLOT(recieveData(int, double)));
And one more thing - for debugging, it's better to output messages to the console using qDebug() << "";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question