Results 1 to 2 of 2

Thread: object handling issue

  1. #1
    Join Date
    Apr 2010
    Posts
    10
    Thanks
    7
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question object handling issue

    Hello,

    I was wondering if you guys could help me out. Here is what i am trying to do...

    I am needing to create an instance of an object. And i need all my other objects to have access to this object. I need to create the instance of the object in my "mainwindow".

    So basically, "mainwindow" is going to have a button. The user clicks the button and a dialog pops up. They put in some input and then the dialog needs to use the object that was created in "mainwindow" to apply some changes. I figured i could just pass the object to the dialog box class... but i dont know how to do that in qt. I am using the gui to create my dialogs and mainwindow. If i need to clarify this, let me know. I would prefer not to post any code, since this is a very general question... should be easy to just answer with some code examples or something.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: object handling issue

    If you have your own dialog class, then just add some method like void setMyObject(MyObject &obj) and call it before dialog.exec();
    But if you want to access this object in many different places and there would be only one instance of it in whole application, then I suggest using Singleton pattern.

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

    prolink007 (11th June 2011)

Similar Threads

  1. Getting std::string object from QString object ( qt3)
    By joseph in forum Qt Programming
    Replies: 11
    Last Post: 28th March 2013, 20:09
  2. handling exceptions
    By mohanakrishnan in forum Qt Programming
    Replies: 3
    Last Post: 25th November 2009, 12:33
  3. writing object to the file(Object Persistance)
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 14:28
  4. Bug in MDI handling
    By daren in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2009, 14:13
  5. Open a QMainWindow Object in QDialog Object
    By chuengchuenghq in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2008, 06:33

Tags for this Thread

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.