Results 1 to 3 of 3

Thread: passing variables in a QWidget constructor when programming with QTDesigner

  1. #1
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default passing variables in a QWidget constructor when programming with QTDesigner

    Hello everyone,
    i am programming in Qt Designer and i want during the QWidget::init() call to pass some variables of my own.. but QtDesigner does not give you anyway to tamper with the form constructor.. and i do not want to affect directly the generated .h and .cpp files under folder .ui/ since they can be overwritten. Is there somethng else i can do?
    Nass

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: passing variables in a QWidget constructor when programming with QTDesigner

    Yes, use the subclassing approach.

  3. #3
    Join Date
    Mar 2006
    Location
    Mexico City
    Posts
    31
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: passing variables in a QWidget constructor when programming with QTDesigner

    Maybe not the best way to do it, but pretty easy. You can write a public method for your Widget, and send your parameters when you call this special method. Maybe a little example can be better:

    Qt Code:
    1. // Somewhere in code, create an instance of some widget
    2. viewer = new Viewer(frame3D, "graf");
    3. // we need to send X and Y dynamic sizes, so:
    4. viewer->param(sizeX, sizeY);
    5. // put 'viewer' on screen...
    6. viewer->show();
    7. //.................
    To copy to clipboard, switch view to plain text mode 
    Note that we call param() before actually showing the widget. This way
    param executes just after construct, and after init(), but before the widget is shown.

    Class Viewer, must have a public method param():
    Qt Code:
    1. void Viewer::param(int X, int Y) {....}
    To copy to clipboard, switch view to plain text mode 

    Hope this aproach can help someone.

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.