Results 1 to 2 of 2

Thread: Custom Widget Constructor

  1. #1
    qtoptus Guest

    Question Custom Widget Constructor

    I'm creating a custom widget to use from the Designer. Currently it's a simple class that has a constructor with no arguments passed. My question is how can I make this widget instantiated such that I specify a different constructor than the default, and pass arguments, for example other objects I may create problematically, not in the Designer. For instance, I have code like this in the form that uses my custom widget, generated by the Designer + VS Qt Plugin:

    MyCustomWidget *myWidget1 = new MyCustomWidget();
    MyCustomWidget *myWidget2 = new MyCustomWidget();

    But I want something like this:

    MyCustomWidget *myWidget1 = new MyCustomWidget(myObject1);
    MyCustomWidget *myWidget2 = new MyCustomWidget(myObject2);

    Where myObject* is created at programming time manually to encapsulate a set of callbacks for example.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widget Constructor

    Designer always uses the default constructor (or actually a constructor taking a QWidget parent). You should allow your widget to accept a myObject pointer through a dedicated call that can be performed after the constructor and you should make that call manually from hand written code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 6th May 2010, 10:09
  2. Replies: 1
    Last Post: 22nd April 2010, 14:34
  3. Replies: 2
    Last Post: 22nd April 2010, 11:44
  4. Replies: 1
    Last Post: 5th November 2006, 23:50
  5. Replies: 9
    Last Post: 8th May 2006, 14:21

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
  •  
Qt is a trademark of The Qt Company.