Answer the question
In order to leave comments, you need to log in
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
#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
void Form::recieveData(int _PopulationSum, double _fitnesMean)
{
points <<QPointF(_PopulationSum,_fitnesMean);
curve->setSamples( points );
curve->attach( ui->Qwt_Widget );
ui->lineEdit->setText("I WORK"); ///проверяет, работает ли функция...не работает..
}
#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); //не могу понять, почему не доходит.
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question