Transfer Data Between Two Forms
-
Hello!
I have a "mainwindow" form named "program" and other form named "addstateform" which is created when I press a button on the "program" form. I want to collect the data from the "addstateform" to do stuff after this form is closed.
I've tried following this tutorial:
https://forum.qt.io/topic/19884/solved-issues-with-signals-and-slot-to-transfer-data-between-two-forms-code-included
But it didn't work. I'm also new to Qt so I don't understand very well the connect function and the signals and slots.My code:
-
addstateform.h
(...)
signals:
void SendData(QString text);
void SendString();
private slots:
void on_Done_clicked();
(...) -
addstateform.cpp
(...)
void AddStateForm::on_Done_clicked()
{
QString text = "HI";
emit SendData(text);
emit SendString();
qDebug() << "Signal Generated";
this->close();
}
(...) -
program.h
(...)
public slots:
void GetData(QString text);
void GetString();
private slots:
void on_SMAddState_clicked();
(...) -
program.cpp
(...)
void Program::GetData(QString text)
{
qDebug() << "Text Received: " << text;
}
void Program::GetString()
{
qDebug() << "Signal Received";
}
void Program::on_SMAddState_clicked()
{
AddStateForm ast;
ast.setModal(true);
connect(ast,SIGNAL(SendData(QString)),this,SLOT(GetData(QString)));
connect(ast,SIGNAL(SendString()),this,SLOT(GetString()));
ast.exec();
(...)
I get this error in both "connect" lines:
no matching function for call to 'Program::connect(AddStateForm&, const char[14], Program* const, const char[13])'I can't figure out what I'm missing/doing wrong.
Would appreciate some help and explanation. Sorry for the long post.
Thank you! -
-
Hi,
It should be:
connect(&ast,SIGNAL(SendData(QString)),this,SLOT(GetData(QString))); connect(&ast,SIGNAL(SendString()),this,SLOT(GetString()));
You need to pass the address of your QObject to the connect function
-
This post is deleted!