Thanks Sir,
Originally Posted by
jpn
Read this article carefully, please: Using a Component in Your Application..
Sir i have already read this document before using Multiple Inheritance method and then setting up Ui.
Originally Posted by
jpn
Still, no setupUi() is being called anywhere. Oh, and in addition to that, it sounds like a class which shouldn't be aware of any UI components in the first place.
In the previous code and this code setupUi() is there in sample.cpp sir, as: -
#######sample.cpp#########
#include <QtGui>
#include "sample.h"
#include "square.h"
mySample
::mySample(QWidget *parent
){
setupUi(this); // this sets up GUI
mySample
::setWindowTitle(QString("Square the given Number"));
connect( startPushButton, SIGNAL( clicked() ), this, SLOT( start() ) );
}
void mySample::start()
{
startPushButton->setEnabled( FALSE );
clearPushButton->setEnabled( FALSE );
int i = inputLineEdit->text().toInt();
Square::Square_of(i);
}
#######sample.cpp#########
#include <QtGui>
#include "sample.h"
#include "square.h"
mySample::mySample(QWidget *parent)
:QWidget( parent )
{
setupUi(this); // this sets up GUI
mySample::setWindowTitle(QString("Square the given Number"));
connect( startPushButton, SIGNAL( clicked() ), this, SLOT( start() ) );
}
void mySample::start()
{
startPushButton->setEnabled( FALSE );
clearPushButton->setEnabled( FALSE );
int i = inputLineEdit->text().toInt();
Square::Square_of(i);
}
To copy to clipboard, switch view to plain text mode
Originally Posted by
jpn
You're already inheriting from Ui::Form and your Square_of() allocates a new Ui::Form every single time it gets called (there's a clear memory leak there).
I had tried resultLineEdit->text() instead of
Ui_Form *frm = new Ui_Form;
frm->resultLineEdit->setText(QString::number(sq,10));
but sir it crashed as i think we cant use widgets in a class where Ui is not setup,right?
As here i have only inherited from Ui::Form class to set the widget.
If i drop the plan to setup widget's property from outside class, can i do like call a function say set_result() from square.cpp
As: -
######square.cpp######
#include<square.h>
#include "sample.h"
#include "ui_sample.h"
void Square::Square_of( int i )
{
int sq = i*i;
mySample::set_result(sq);
}
######square.cpp######
#include<square.h>
#include "sample.h"
#include "ui_sample.h"
void Square::Square_of( int i )
{
int sq = i*i;
mySample::set_result(sq);
}
To copy to clipboard, switch view to plain text mode
Where set_result() is a static function implemented in sample.cpp as: -
void mySample::set_result(int ans)
{
resultLineEdit->setText(QString::number(ans,10));
}
But while doing so i got error
{
sample.cpp: In static member function `static void mySample::set_result(int)':
ui_sample.h:34: error: invalid use of member `Ui_Form::resultLineEdit' in static
member function
sample.cpp:111: error: from this location
}
So is it like i can't setup widgets from static functions?
To avoid this if i try to create an object of sample.cpp class in square.cpp class for calling the function it will again setup the Ui, right? which is undesirable
Am Very Sorry Sir as disturbing you so much. But i will be grateful to you Sir if helped.
Thanks in advance again Sir.
Bookmarks