Results 1 to 7 of 7

Thread: promoted widgets using QT designer is not calling its constructor

  1. #1
    Join Date
    Nov 2009
    Posts
    60
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default promoted widgets using QT designer is not calling its constructor

    Dear All,

    I made a subclass of QLineEdit class and implemented its constructor and keyPressEvent event handler,then I promoted one of the instances of QLineEdit to subclass with QT Designer by right clicking and selecting the promote option. I am able to call keyPressEvent() method in my application. however the constructor of this subclass is never called.

    header file.
    Qt Code:
    1. class printlineEdit : public QLineEdit
    2. {
    3. //Q_OBJECT
    4.  
    5. public:
    6. //signals:
    7. // void escapePress();
    8. public:
    9.  
    10. printlineEdit(QWidget *parent = 0);
    11. void keyPressEvent( QKeyEvent *event );
    12. unsigned int ValuePut,val;
    13.  
    14. };
    To copy to clipboard, switch view to plain text mode 


    its corresponding c++ file.

    Qt Code:
    1. printlineEdit::printlineEdit(QWidget *parent):QLineEdit(parent)
    2. {
    3. ValuePut=0;
    4. //selectionStart ();
    5. //setCursorPosition(0);
    6. printf("Inside printline constr\n");
    7. }
    8.  
    9. void printlineEdit::keyPressEvent(QKeyEvent *event)
    10. {
    11. bool flag=0;
    12. QString ch("");
    13.  
    14. switch(event->key())
    15. {
    16. case Qt::Key_Left:
    17. break;
    18. case Qt::Key_Right:
    19.  
    20. break;
    21. case Qt::Key_Up:
    22. break;
    23. case Qt::Key_Down:
    24.  
    25. break;
    26. case Qt::Key_Return:
    27. flag=1;
    28. printf("Enter Pressed\n");
    29. break;
    30. }
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

    Now for the above code the constructor printlineEdit(QWidget *parent) is never called.

    Kindly tell me how to implement a constructor in these scenario.

    Ratheendran
    Last edited by wysota; 3rd April 2011 at 08:37. Reason: changed [quote] to [code]

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

    Default Re: promoted widgets using QT designer is not calling its constructor

    How do you know it is never called?
    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.


  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: promoted widgets using QT designer is not calling its constructor

    Maybe other constructor for QLineEdit is called, have you tried to implement the other one ?
    Qt Code:
    1. class printlineEdit : public QLineEdit
    2. {
    3. //Q_OBJECT
    4.  
    5. public:
    6. //signals:
    7. // void escapePress();
    8. public:
    9.  
    10. printlineEdit(QWidget *parent = 0);
    11. printlineEdit(const QString& text, QWidget *parent = 0);
    12. ...
    13. ...
    14. // .cpp
    15. printlineEdit::printlineEdit(const QString& text, QWidget *parent):QLineEdit(text,parent)
    16. {
    17. ValuePut=0;
    18. //selectionStart ();
    19. //setCursorPosition(0);
    20. printf("Inside printline constr 2\n");
    21. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: promoted widgets using QT designer is not calling its constructor

    uic only calls the constructor that takes a parent:
    Qt Code:
    1. void setupUi(QWidget *Form)
    2. {
    3. if (Form->objectName().isEmpty())
    4. Form->setObjectName(QString::fromUtf8("Form"));
    5. Form->resize(400, 300);
    6. lineEdit = new printlineEdit(Form);
    7. lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    8. lineEdit->setGeometry(QRect(80, 40, 113, 20));
    9.  
    10. retranslateUi(Form);
    11.  
    12. QMetaObject::connectSlotsByName(Form);
    13. } // setupUi
    To copy to clipboard, switch view to plain text mode 
    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.


  5. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: promoted widgets using QT designer is not calling its constructor

    uic only calls the constructor that takes a parent
    You are right
    Take a look into the ui_*.h file for this form, this way you'll know what is called for your line edit.

  6. #6
    Join Date
    Nov 2009
    Posts
    60
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: promoted widgets using QT designer is not calling its constructor

    Thanks for your support.

    I was able to figure out the issue.

    I deleted the promoted widget and created them again,so the text message which I update in the constructor is now visible.

    issue is caused because,I used ui designer to put the default text, once I compiled,then I removed the text from ui designer and implemented it in constructor using setText() method. This was creating the confusion.

    Another thing I want to ask is there way to call a user defined constructor using the same method.

    Ratheendran

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

    Default Re: promoted widgets using QT designer is not calling its constructor

    No, Designer always calls the constructor with a parent argument.
    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. Promoted widgets in Qt Designer
    By martinb0820 in forum Qt Tools
    Replies: 1
    Last Post: 9th June 2010, 15:07
  2. Replies: 0
    Last Post: 24th October 2009, 07:38
  3. Call Constructor within Designer
    By NoRulez in forum Qt Programming
    Replies: 22
    Last Post: 24th June 2009, 08:27
  4. Replies: 4
    Last Post: 12th August 2008, 01:55
  5. Promoted widgets and layout boxes
    By notsonerdysunny in forum Qt Tools
    Replies: 3
    Last Post: 2nd May 2007, 14:15

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.