Results 1 to 6 of 6

Thread: basic question: getting value from qwidget and use it in mainapplication

  1. #1
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default basic question: getting value from qwidget and use it in mainapplication

    hi

    Please I am new in qt4 world 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?

  2. #2
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: basic question: getting value from qwidget and use it in mainapplication

    We can't solve problems by using the same kind of thinking we used when we created them

  3. The following user says thank you to sunil.thaha for this useful post:

    QiT (2nd August 2006)

  4. #3
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: basic question: getting value from qwidget and use it in mainapplication

    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.

  5. #4
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: basic question: getting value from qwidget and use it in mainapplication

    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

    Qt Code:
    1. // Represents whatever widget
    2. class ClassIAmInterestedIn {
    3. public:
    4. void tryToAccessMe();
    5. }
    6.  
    7.  
    8. // Represents Container Holding the widget ( Maybe a Dialog )
    9.  
    10. class IhaveObjectYouAreInterestedIn{
    11.  
    12. private:
    13. ClassIAmInterestedIn objectOfThatClass;
    14. };
    15.  
    16.  
    17.  
    18. // You are working in this class
    19. class IAmHere {
    20. public:
    21. void someMethod(){
    22. IhaveObjectYouAreInterestedIn obj;
    23. obj.doSomeThingInteresting();
    24.  
    25. // Now there is achange in IhaveObjectYouAreInterestedIn::objectOfThatClass;
    26. // and U will have to access objectOfThatClass::tryToAccessMe()
    27. // Fig out how to access that
    28. }
    29. };
    To copy to clipboard, switch view to plain text mode 
    We can't solve problems by using the same kind of thinking we used when we created them

  6. #5
    Join Date
    Jul 2006
    Location
    Coimbatore,India
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: basic question: getting value from qwidget and use it in mainapplication

    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

  7. #6
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: basic question: getting value from qwidget and use it in mainapplication

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.