To display output of a function from mainform to any other new form
Hello all
i want to display ouput of a function defined in mainform(binary) to next form (Analyze) . means whn i press push button 2 output displayed on line edit of next form(Analyze)?? how m able to do that plz Help???
binary.cpp
Code:
#include "binary.h"
#include "ui_binary.h"
#include "ui_analyze.h"
ui(new Ui::binary)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(openAnalyze()));
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(text()));
}
void binary::openAnalyze()
{
myAnalzye= new Analyze();
myAnalyze->show();
}
void binary::text()
{
ui->lineEdit->setText(set);
}
binary::~binary()
{
delete ui;
}
Re: To display output of a function from mainform to any other new form
Implement a signal in "binary" that is emitted when the button is pushed. The signal would look something like this:
Code:
signals:
void button2Pushed
( const QString & text
);
In your "Analyze" dialog, implement a slot that is connected to that signal:
Code:
public slots:
void onButton2Push
( const QString & text
);
In your "openAnalyze" method, connect the signal to the slot:
Code:
connect( this,
SIGNAL( onButton2Push
( const QString & ) ), myAnalyze,
SLOT( onButton2Push
( const QString & ) ) );
In the binary class text() method, emit the signal:
Code:
emit button2Pushed( set );
By the way, in your code line 22 is a memory leak.
Re: To display output of a function from mainform to any other new form
i got following error
binary.h
Code:
#ifndef BINARY_H
#define BINARY_H
#include <QMainWindow>
#include"analyze.h"
namespace Ui {
class binary;
}
{
Q_OBJECT
public:
explicit binary
(QWidget *parent
= 0);
~binary();
public slots:
void openAnalyze();
public slots:
void text();
signals:
void button2Pushed
( const QString & text
);
private:
Analyze *myAnalyze;
private:
Ui::binary *ui;
};
#endif // BINARY_H
binary.cpp
Code:
#include "binary.h"
#include "ui_binary.h"
#include "ui_analyze.h"
ui(new Ui::binary)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(openAnalyze()));
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(text()));
}
void binary::openAnalyze()
{
myAnalyze= new Analyze();
myAnalyze->show();
connect( this,
SIGNAL( onButton2Push
( const QString & ) ), myAnalyze,
SLOT( onButton2Push
( const QString & ) ) );
}
void binary::text()
{
ui->lineEdit->setText(set);
emit button2Pushed( set );
}
binary::~binary()
{
delete ui;
}
analyze.h
Code:
#ifndef ANALYZE_H
#define ANALYZE_H
#include <QDialog>
namespace Ui {
class Analyze;
}
{
Q_OBJECT
public:
explicit Analyze
(QWidget *parent
= 0);
~Analyze();
public slots:
void onButton2Push
( const QString & text
);
private:
Ui::Analyze *ui;
};
#endif // ANALYZE_H
analyze.cpp
Code:
#include "analyze.h"
#include "ui_analyze.h"
Analyze
::Analyze(QWidget *parent
) : ui(new Ui::Analyze)
{
ui->setupUi(this);
}
void Analyze
::onButton2Push( const QString & text
) {
}
Analyze::~Analyze()
{
delete ui;
}
i gott following error plz help
starting /home/nawazbaig/BinaryAnalyzer-build-desktop-Qt_4_8_1_in_PATH__System__Release/BinaryAnalyzer...
Object::connect: No such signal binary::onButton2Push( const QString & )
Object::connect: (sender name: 'binary')
Object::connect: (receiver name: 'Analyze')
/home/nawazbaig/BinaryAnalyzer-build-desktop-Qt_4_8_1_in_PATH__System__Release/BinaryAnalyzer exited with code 0
plz help i displayed code with changes but no result
Re: To display output of a function from mainform to any other new form
Quote:
Object::connect: No such signal binary:: onButton2Push( const QString & )
So? Qt is telling you the truth. There is no binary:: onButton2Push() signal.
What does line 24 in your binary.h code say?
Code:
void button2Pushed
( const QString & text
);
And line 23 in binary.cpp is still a memory leak. If you don't see why, think about what happens the second time that openAnalyze() is called.
Re: To display output of a function from mainform to any other new form
HI
I am pretty new plz tell me how i overcome this memory leak plz ?????
i correct button2Pushed
plz help
No error but no ouput on analyze dialog when i press push button 2 frombinary
Binary.h
Code:
#ifndef BINARY_H
#define BINARY_H
#include <QMainWindow>
#include"analyze.h"
namespace Ui {
class binary;
}
{
Q_OBJECT
public:
explicit binary
(QWidget *parent
= 0);
~binary();
public slots:
void openAnalyze();
public slots:
void text();
signals:
void button2Pushed
( const QString & text
);
private:
Analyze *myAnalyze;
private:
Ui::binary *ui;
};
#endif // BINARY_H
Binary.cpp
Code:
#include "binary.h"
#include "ui_binary.h"
#include "ui_analyze.h"
ui(new Ui::binary)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(openAnalyze()));
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(text()));
}
void binary::openAnalyze()
{
myAnalyze= new Analyze();
myAnalyze->show();
connect( this,
SIGNAL( button2Pushed
( const QString & ) ), myAnalyze,
SLOT( onButton2Push
( const QString & ) ) );
}
void binary::text()
{
emit button2Pushed( set );
}
binary::~binary()
{
delete ui;
}
Analyze.h
Code:
#ifndef ANALYZE_H
#define ANALYZE_H
#include <QDialog>
namespace Ui {
class Analyze;
}
{
Q_OBJECT
public:
explicit Analyze
(QWidget *parent
= 0);
~Analyze();
public slots:
void onButton2Push
( const QString & text
);
private:
Ui::Analyze *ui;
};
#endif // ANALYZE_H
Analyze.cpp
Code:
#include "analyze.h"
#include "ui_analyze.h"
Analyze
::Analyze(QWidget *parent
) : ui(new Ui::Analyze)
{
ui->setupUi(this);
}
void Analyze
::onButton2Push( const QString & text
) {
}
Analyze::~Analyze()
{
delete ui;
}
Re: To display output of a function from mainform to any other new form
Code:
void Analyze
::onButton2Push( const QString & text
) {
}
Of course there's no output. You aren't doing anything in this slot. Do you think that by some magic, Qt is supposed to know that "text" should appear in some line edit on the Analyze dialog? You have to tell it where to put the text if you want it to appear. (Don't ask how to do that. If you don't understand something so simple, go back and study some Qt examples until you understand it. We aren't here to write your programs for you).
Fix the memory leak by moving the "myAnalyze = new Analyze();" line into the constructor for the binary class (and change it to "myAnalyze = new Analyze( this )" so the instance gets destroyed when binary is destroyed), and move the "connect" there also, after the Analyze instance is created. That way, you create only one instance of Analyze, and you use the same one each time openAnalyze() is called.
Re: To display output of a function from mainform to any other new form
Thanks...a lot
for ur help
Re: To display output of a function from mainform to any other new form
So if you rewrite your constructor this way, you do not need the "openAnalyze()" slot at all:
Code:
ui(new Ui::binary)
{
ui->setupUi(this);
myAnalyze = new Analyze( this );
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(text()));
connect(ui->pushButton, SIGNAL(clicked()), myAnalyze, SLOT( show() ) );
connect( this,
SIGNAL( button2Pushed
( const QString & ) ), myAnalyze,
SLOT( onButton2Push
( const QString & ) ) );
}
That is, you can connect the pushbutton's clicked signal() directly to the myAnalyze show() slot, because after you move the code around, there isn't anything except a call to show() in the openAnalyze() slot. You can get rid of it.