Results 1 to 15 of 15

Thread: Wierd behaviour after resizing child dialogue

  1. #1
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Wierd behaviour after resizing child dialogue

    By the QT designer, I made this QMainWindow, who has a button, and when click the button, a child dialog will pop up.

    At first when the MainWindow and the dialogue were produced at arround the same time, I had the dialogue in the center of the mainwindow. When I click on "X" to close the child dialogue , the dialogue shuts down but the mainwindow stays opened.

    After a while, I found that the child dialogue size is too small, so I manually enlarged the size of the dialogue to more than even the mainwindow. Now this time whenever I close the child dialogue, the mainwindow will be closed after the childe is closed.

    Now I resize the child dialogue back to the original header class. Biut the same problem stil l happens.


    Anyone has any idea what how to solve this problem?


    Thanks thanks a lot.

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

    Default Re: Wierd behaviour after resizing child dialogue

    Maybe the application crashes? Could you check that?

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

    KaKa (17th March 2007)

  4. #3
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Wierd behaviour after resizing child dialogue

    Hello,

    thanks for replying. I actually have three buttons, directing to three different dialogs. and only the first one on the left will have such strange behaviour even before resizing.

    Does it have anything to do with the main button of the widget or something? I am totally new to this, so idea might be totally off track, so

    Thanks!!!

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

    Default Re: Wierd behaviour after resizing child dialogue

    Can we see the code?

  6. #5
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Wierd behaviour after resizing child dialogue

    It is generated by the Designer. But I will still post the code here, see if it helps:

    Qt Code:
    1. #ifndef UI_NEW311_H
    2. #define UI_NEW311_H
    3.  
    4. #include <QtCore/QVariant>
    5. #include <QtGui/QAction>
    6. #include <QtGui/QApplication>
    7. #include <QtGui/QButtonGroup>
    8. #include <QtGui/QHBoxLayout>
    9. #include <QtGui/QMainWindow>
    10. #include <QtGui/QPushButton>
    11. #include <QtGui/QSpacerItem>
    12. #include <QtGui/QStatusBar>
    13. #include <QtGui/QToolBar>
    14. #include <QtGui/QWidget>
    15.  
    16. class Ui_New311Class
    17. {
    18. public:
    19. QWidget *centralWidget;
    20. QWidget *widget;
    21. QHBoxLayout *hboxLayout;
    22. QPushButton *SimpDlg1;
    23. QSpacerItem *spacerItem;
    24. QPushButton *SimpDlg2;
    25. QSpacerItem *spacerItem1;
    26. QPushButton *SimpDlg3;
    27. QToolBar *mainToolBar;
    28. QStatusBar *statusBar;
    29.  
    30. void setupUi(QMainWindow *New311Class)
    31. {
    32. New311Class->setObjectName(QString::fromUtf8("New311Class"));
    33. centralWidget = new QWidget(New311Class);
    34. centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
    35. widget = new QWidget(centralWidget);
    36. widget->setObjectName(QString::fromUtf8("widget"));
    37. widget->setGeometry(QRect(80, 50, 423, 25));
    38. hboxLayout = new QHBoxLayout(widget);
    39. hboxLayout->setSpacing(6);
    40. hboxLayout->setMargin(0);
    41. hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
    42. SimpDlg1 = new QPushButton(widget);
    43. SimpDlg1->setObjectName(QString::fromUtf8("SimpDlg1"));
    44.  
    45. hboxLayout->addWidget(SimpDlg1);
    46.  
    47. spacerItem = new QSpacerItem(81, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    48.  
    49. hboxLayout->addItem(spacerItem);
    50.  
    51. SimpDlg2 = new QPushButton(widget);
    52. SimpDlg2->setObjectName(QString::fromUtf8("SimpDlg2"));
    53.  
    54. hboxLayout->addWidget(SimpDlg2);
    55.  
    56. spacerItem1 = new QSpacerItem(91, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    57.  
    58. hboxLayout->addItem(spacerItem1);
    59.  
    60. SimpDlg3 = new QPushButton(widget);
    61. SimpDlg3->setObjectName(QString::fromUtf8("SimpDlg3"));
    62.  
    63. hboxLayout->addWidget(SimpDlg3);
    64.  
    65. New311Class->setCentralWidget(centralWidget);
    66. mainToolBar = new QToolBar(New311Class);
    67. mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
    68. mainToolBar->setOrientation(Qt::Horizontal);
    69. New311Class->addToolBar(static_cast<Qt::ToolBarArea>(4), mainToolBar);
    70. statusBar = new QStatusBar(New311Class);
    71. statusBar->setObjectName(QString::fromUtf8("statusBar"));
    72. New311Class->setStatusBar(statusBar);
    73.  
    74. retranslateUi(New311Class);
    75.  
    76. QSize size(600, 400);
    77. size = size.expandedTo(New311Class->minimumSizeHint());
    78. New311Class->resize(size);
    79.  
    80.  
    81. QMetaObject::connectSlotsByName(New311Class);
    82. } // setupUi
    83.  
    84. void retranslateUi(QMainWindow *New311Class)
    85. {
    86. New311Class->setWindowTitle(QApplication::translate("New311Class", "New311", 0, QApplication::UnicodeUTF8));
    87. SimpDlg1->setText(QApplication::translate("New311Class", "SimpDlg1", 0, QApplication::UnicodeUTF8));
    88. SimpDlg2->setText(QApplication::translate("New311Class", "SimpDlg2", 0, QApplication::UnicodeUTF8));
    89. SimpDlg3->setText(QApplication::translate("New311Class", "SimpDlg3", 0, QApplication::UnicodeUTF8));
    90. Q_UNUSED(New311Class);
    91. } // retranslateUi
    92.  
    93. };
    94.  
    95. namespace Ui {
    96. class New311Class: public Ui_New311Class {};
    97. } // namespace Ui
    98.  
    99. #endif
    To copy to clipboard, switch view to plain text mode 

    The above is the code for the main window, Now I paste the first dialog code below:

    Qt Code:
    1. #ifndef UI_SIMPDLG1_H
    2. #define UI_SIMPDLG1_H
    3.  
    4. #include <QtCore/QVariant>
    5. #include <QtGui/QAction>
    6. #include <QtGui/QApplication>
    7. #include <QtGui/QButtonGroup>
    8. #include <QtGui/QDialog>
    9. #include <QtGui/QLabel>
    10. #include <QtGui/QLineEdit>
    11. #include <QtGui/QPushButton>
    12.  
    13. class Ui_simpDlg1Class
    14. {
    15. public:
    16. QLabel *orders2;
    17. QLabel *prime3itself;
    18. QLabel *prime5itself;
    19. QLabel *RestrLabel;
    20. QPushButton *Reset3;
    21. QLineEdit *lineEdit_2;
    22. QLineEdit *RestLineEdit;
    23.  
    24. void setupUi(QDialog *simpDlg1Class)
    25. {
    26. simpDlg1Class->setObjectName(QString::fromUtf8("simpDlg1Class"));
    27. orders2 = new QLabel(simpDlg1Class);
    28. orders2->setObjectName(QString::fromUtf8("orders2"));
    29. orders2->setGeometry(QRect(30, 30, 313, 20));
    30. prime3itself = new QLabel(simpDlg1Class);
    31. prime3itself->setObjectName(QString::fromUtf8("prime3itself"));
    32. prime3itself->setGeometry(QRect(350, 60, 20, 20));
    33. prime5itself = new QLabel(simpDlg1Class);
    34. prime5itself->setObjectName(QString::fromUtf8("prime5itself"));
    35. prime5itself->setGeometry(QRect(30, 60, 12, 20));
    36. RestrLabel = new QLabel(simpDlg1Class);
    37. RestrLabel->setObjectName(QString::fromUtf8("RestrLabel"));
    38. RestrLabel->setGeometry(QRect(30, 100, 187, 16));
    39. OK3 = new QPushButton(simpDlg1Class);
    40. OK3->setObjectName(QString::fromUtf8("OK3"));
    41. OK3->setGeometry(QRect(310, 180, 75, 23));
    42. Reset3 = new QPushButton(simpDlg1Class);
    43. Reset3->setObjectName(QString::fromUtf8("Reset3"));
    44. Reset3->setGeometry(QRect(230, 180, 75, 23));
    45. lineEdit_2 = new QLineEdit(simpDlg1Class);
    46. lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
    47. lineEdit_2->setGeometry(QRect(50, 60, 295, 20));
    48. RestLineEdit = new QLineEdit(simpDlg1Class);
    49. RestLineEdit->setObjectName(QString::fromUtf8("RestLineEdit"));
    50. RestLineEdit->setGeometry(QRect(50, 130, 291, 20));
    51.  
    52. retranslateUi(simpDlg1Class);
    53.  
    54. QSize size(400, 300);
    55. size = size.expandedTo(simpDlg1Class->minimumSizeHint());
    56. simpDlg1Class->resize(size);
    57.  
    58.  
    59. QMetaObject::connectSlotsByName(simpDlg1Class);
    60. } // setupUi
    61.  
    62. void retranslateUi(QDialog *simpDlg1Class)
    63. {
    64. simpDlg1Class->setWindowTitle(QApplication::translate("simpDlg1Class", "simpDlg1", 0, QApplication::UnicodeUTF8));
    65. orders2->setText(QApplication::translate("simpDlg1Class", "Please input the orders ", 0, QApplication::UnicodeUTF8));
    66. prime3itself->setText(QApplication::translate("simpDlg1Class", "-3'", 0, QApplication::UnicodeUTF8));
    67. prime5itself->setText(QApplication::translate("simpDlg1Class", "5'-", 0, QApplication::UnicodeUTF8));
    68. RestrLabel->setText(QApplication::translate("simpDlg1Class", "Please enter restrictions here(optional)", 0, QApplication::UnicodeUTF8));
    69. OK3->setText(QApplication::translate("simpDlg1Class", "Ok", 0, QApplication::UnicodeUTF8));
    70. Reset3->setText(QApplication::translate("simpDlg1Class", "Reset", 0, QApplication::UnicodeUTF8));
    71. Q_UNUSED(simpDlg1Class);
    72. } // retranslateUi
    73.  
    74. };
    75.  
    76. namespace Ui {
    77. class simpDlg1Class: public Ui_simpDlg1Class {};
    78. } // namespace Ui
    79.  
    80. #endif // UI_SIMPDLG1_H
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Wierd behaviour after resizing child dialogue

    I meant the code of the class implementing the dialog and the main window, not their ui.

  8. #7
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Lightbulb Re: Wierd behaviour after resizing child dialogue

    Well, the code for the code implementing the main window and dialog is very simple. only some event handlers for buttons. But I still paste it below:

    1. Main Window:
    Qt Code:
    1. #include "new311.h"
    2. #include "SimpDlg1.h"
    3. #include "SimpDlg2.h"
    4. #include "SimpDlg3.h"
    5.  
    6. new311::new311(QWidget *parent, Qt::WFlags flags)
    7. : QMainWindow(parent, flags)
    8. {
    9. ui.setupUi(this);
    10. }
    11.  
    12. new311::~new311()
    13. {
    14.  
    15. }
    16.  
    17.  
    18. void new311::on_SimpDlg1_clicked()
    19. {
    20. SimpDlg1 dialog1(this);
    21. dialog1.exec();
    22. }
    23.  
    24. void new311::on_SimpDlg2_clicked()
    25. {
    26. SimpDlg2 dialog2(this);
    27. dialog2.exec();
    28. }
    29.  
    30. void new311::on_SimpDlg3_clicked()
    31. {
    32. SimpDlg3 dialog3(this);
    33. dialog3.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 

    2. The dialog

    Qt Code:
    1. #include <QDialog.h>
    2. #include <qmessagebox.h>
    3. #include "simpDlg1.h"
    4. #include "simpDlg1Driver.h"
    5. #include "ui_simpDlg1.h"
    6.  
    7.  
    8. simpDlg1::simpDlg1(QWidget *parent)
    9. : QDialog(parent)
    10. {
    11. ui.setupUi(this);
    12. }
    13.  
    14. simpDlg1::~simpDlg1()
    15. {
    16. delete param1;
    17. delete param2;
    18. }
    19.  
    20.  
    21. void simpDlg1::on_Reset3_clicked()
    22. {
    23. ui.lineEdit_2->clear();
    24. ui.RestLineEdit->clear();
    25. }
    26.  
    27. void simpDlg1::on_OK3_clicked()
    28. {
    29. param1=new QString();
    30. *param1=ui.lineEdit_2->text();
    31. simpDlg1Driver simpDriver=new simpDlg1Driver();
    32. simpDriver.setsimpDlg1(this);
    33. int success=simpDriver.checksimpDlg1(*param1);
    34. if(success==1)
    35. {
    36. QMessageBox *warmessage=new QMessageBox(this);
    37. warmessage->setText("Please enter a string");
    38. warmessage->setIcon(QMessageBox::Critical);
    39. warmessage->exec();
    40. }
    41. }
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot!

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

    Default Re: Wierd behaviour after resizing child dialogue

    Why do you use pointers here? What happens if you declare param1 and param2 as objects and not pointers to objects? If you need to modify some object, you can pass it by reference. You have a memory leak on the "warmessage" object. Does the application crash or simply close because last window gets closed? The code you have shown us shouldn't cause the main window to close, the only possibility I see is that the application crashed because an improper use of one of the pointers.

  10. The following user says thank you to wysota for this useful post:

    KaKa (18th March 2007)

  11. #9
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Wierd behaviour after resizing child dialogue

    It is actually because QString param1=new QString() insdead of QString *param1=new QString(); compiler will complain, saying that the new QString() returns a pointer which is not matching the type of param1 or something like that.

    However, since you said it will cause memory leak, I guess I will change them to objects.

    So by pass by reference you mean I can do this:
    QString param1; &param1=new QString(); ?

    Before my application just simply totally shuts done after I shuts done the first dialog, but now after adding a new child dialog to the first dialog, when this new dialog shut down, its two parents will freez, and an exception will be thrown.

    Don't know if you still have clue of what my question is and what might be the explanation.

  12. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Wierd behaviour after resizing child dialogue

    How about something like this:
    Qt Code:
    1. class simpDlg1
    2. {
    3. ...
    4. private:
    5. QString param1; // not QString*
    6. QString param2; // not QString*
    7. }
    8.  
    9. simpDlg1::~simpDlg1()
    10. {
    11. // delete param1; <-- no more needed
    12. // delete param2; <-- no more needed
    13. }
    14.  
    15. void simpDlg1::on_OK3_clicked()
    16. {
    17. param1=ui.lineEdit_2->text();
    18. simpDlg1Driver simpDriver; // notice the difference
    19. simpDriver.setsimpDlg1(this);
    20. int success=simpDriver.checksimpDlg1(param1);
    21. if(success==1)
    22. {
    23. QMessageBox warmessage(this); // notice the difference
    24. warmessage.setText("Please enter a string");
    25. warmessage.setIcon(QMessageBox::Critical);
    26. warmessage.exec(); // blocks until the message is closed
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 
    Unlike Java, in C++ you don't create everything with "new".
    J-P Nurmi

  13. The following user says thank you to jpn for this useful post:

    KaKa (18th March 2007)

  14. #11
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Wierd behaviour after resizing child dialogue

    O wow. I get it now! Thanks!

  15. #12
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Red face Re: Wierd behaviour after resizing child dialogue

    Sorry I have to reopen this question:

    I tried the code jpn suggested, the code worked fine, but the problem is still there.

    Also for those widgets, for example, the initialization of them, the formal way is

    Wedgit awedgit=new Wedgit(* parent); or awdgit=Wedgit(*parent);?

    Then this means the parent, has to be a pointer when instantiated? '

    Then that means in the Child class, I will have to declare some pointers to Widget (that is the parents) so that means the memory leak is not preventable?

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

    Default Re: Wierd behaviour after resizing child dialogue

    You don't have to declare anything.

    Qt Code:
    1. class MyWidget : public QWidget {
    2. public:
    3. MyWidget(QWidget *parent =0 ) : QWidget(parent){
    4. QLabel *lab = new QLabel(this); // current object (this) is set as the parent)
    5. lab->setText("TEST");
    6. }
    7. };
    8.  
    9. int main(int argc, char **argv){
    10. QApplication app(argc, argv);
    11. MyWidget wgt;
    12. wgt.show();
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 
    When "wgt" is destroyed so are all its child QObjects (the label being one of them). No memory leak and no pointers declared (and no dangling pointers).

  17. #14
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Wierd behaviour after resizing child dialogue



    What I meant was actually
    say in your example,
    the MyWedgit, it is a child of another wedgit(for example YourWedigt, then when we initialize a MyWedgit object we have to use a pointer to YourWedgit as the first parameter. (I tried use simply an object instead of a pointer, and the compiler complained, either saying I cannot access the private object, or says cannot convert an object to a pointer).

    The case you were showing me with "this", as the tool tip told me before, "this" was a pointer itself.

    I guess I have created a bit too many classes to call one from another?

    hope I made myself clear... and hope what I just written isn't something stupid...

  18. #15
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Wierd behaviour after resizing child dialogue

    Actually never mind...the problem isn't that serious any more. As long as I wait until the QT evaluation warning panel disappear, and run my program, it doesn't show up any more.

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.