PDA

View Full Version : basic question: getting value from qwidget and use it in mainapplication



QiT
2nd August 2006, 11:05
hi :D

Please I am new in qt4 world:confused: My application is composed of a mainapplication window and a qwidget.
I want get the value qstring from the lineedit.text(); in the qwidget to use it in the main window. so Howto?:crying:

sunil.thaha
2nd August 2006, 11:24
Refer
http://www.digitalfanatics.org/projects/qt_tutorial/chapter07.html

QiT
3rd August 2006, 10:31
Hi

The tutorial presents QT3 but i need QT4 solution. I need just how to get information (qstrings or int) from a QDialog or Qwidget to use them in the main window.

sunil.thaha
4th August 2006, 06:47
there are lots of oss available in the links section, or the Qt Software section. go through those.

It's just a basic question of accessing a member variable's methods

What will you do in this situation




// Represents whatever widget
class ClassIAmInterestedIn {
public:
void tryToAccessMe();
}


// Represents Container Holding the widget ( Maybe a Dialog )

class IhaveObjectYouAreInterestedIn{

private:
ClassIAmInterestedIn objectOfThatClass;
};



// You are working in this class
class IAmHere {
public:
void someMethod(){
IhaveObjectYouAreInterestedIn obj;
obj.doSomeThingInteresting();

// Now there is achange in IhaveObjectYouAreInterestedIn::objectOfThatClass;
// and U will have to access objectOfThatClass::tryToAccessMe()
// Fig out how to access that
}
};

vishva
4th August 2006, 08:45
hi,

Do you want get data from QLineEdit box ?

the follwing function should return what ever lineedit box contains

QString displayText() and QString text();

more details ,refer Qt Assistant

sumsin
4th August 2006, 11:12
If u want to get the value of text box from a QWidget to MainWindow,

declare an instance of QWidget say MyQWidget in ur MainWindow then u can get the value by MyQWidget->MyTextBox->text();

Or if u r doing all the things in designer(i.e. u r not creating any implementation header or source file) then the place where u r actually getting the text string, store this in an extern variable and access this extern variable in ur MainWindow.
But I would not recommend this approach, its better that u should create the implementation files for both ur QWidget and MainWindow, then implement the functionality there.