Results 1 to 5 of 5

Thread: compiled successfully but form is not displayed

  1. #1
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default compiled successfully but form is not displayed

    I am a newbie for c++ as well as qt. I am trying some example, which i pasted it for
    easy understanding. I am trying to compile it through qmake and make command line tool. It compiles successfully but when i try to execute it no form is displayed.
    please look into the code help me where i am doing mistake....

    Qt Code:
    1. //finddialog.h file
    2.  
    3. #ifndef FINDDIALOG_H
    4. #define FINDDIALOG_H
    5.  
    6. #include<QDialog>
    7.  
    8. class QLineEdit;
    9. class QCheckBox;
    10. class QLabel;
    11.  
    12. class FindDialog:public QDialog
    13. {
    14. Q_OBJECT
    15. public:
    16. FindDialog(QWidget *parent=0);
    17.  
    18. signals:
    19. void findNext(const QString &str,Qt::CaseSensitivity cs);
    20. void findPrevious(const QString &str,Qt::CaseSensitivity cs);
    21.  
    22. public slots:
    23. void findClicked();
    24. void enableFindButton(const QString &text);
    25.  
    26. private:
    27. QLabel *label;
    28. QLineEdit *lineEdit;
    29. QCheckBox *caseCheckBox;
    30. QCheckBox *backwardCheckBox;
    31. QPushButton *findButton;
    32. QPushButton *closeButton;
    33. };
    34. #endif
    35. //************************************************
    36. //finddialog.cpp
    37. #include<QtGui>
    38. #include "finddialog.h"
    39.  
    40. FindDialog::FindDialog(QWidget *parent):QDialog(parent)
    41. {
    42. label=new QLabel("Find &what: ");
    43. lineEdit=new QLineEdit;
    44. label->setBuddy(lineEdit);
    45.  
    46. caseCheckBox=new QCheckBox("Match &case");
    47. backwardCheckBox=new QCheckBox("Search &backward");
    48.  
    49. findButton=new QPushButton("&Find");
    50. findButton->setDefault(true);
    51. findButton->setEnabled(false);
    52.  
    53. closeButton=new QPushButton("Close");
    54.  
    55. connect(lineEdit,SIGNAL(textChanged(const QString &)),
    56. this,SLOT(enableFindButton(const QString &)));
    57. connect(findButton,SIGNAL(clicked()),
    58. this,SLOT(findClicked()));
    59. connect(closeButton,SIGNAL(clicked()),
    60. this,SLOT(close()));
    61.  
    62. QHBoxLayout *topleftLayout=new QHBoxLayout;
    63. topleftLayout->addWidget(label);
    64. topleftLayout->addWidget(lineEdit);
    65.  
    66. QVBoxLayout *leftLayout=new QVBoxLayout;
    67. leftLayout->addLayout(topleftLayout);
    68. leftLayout->addWidget(caseCheckBox);
    69. leftLayout->addWidget(backwardCheckBox);
    70.  
    71. QVBoxLayout *rightLayout=new QVBoxLayout;
    72. rightLayout->addWidget(findButton);
    73. rightLayout->addWidget(closeButton);
    74. rightLayout->addStretch();
    75.  
    76. QHBoxLayout *mainLayout=new QHBoxLayout;
    77. rightLayout->addLayout(leftLayout);
    78. rightLayout->addLayout(rightLayout);
    79. setLayout(mainLayout);
    80.  
    81. setWindowTitle("Find");
    82. setFixedHeight(sizeHint().height());
    83. }
    84.  
    85. void FindDialog::findClicked()
    86. {
    87. QString text=lineEdit->text();
    88. Qt::CaseSensitivity cs=caseCheckBox->isChecked()?
    89. Qt::CaseSensitive:Qt::CaseInsensitive;
    90.  
    91. if(backwardCheckBox->isChecked())
    92. {
    93. emit findPrevious(text,cs);
    94. }
    95. else
    96. {
    97. emit findNext(text,cs);
    98. }
    99. }
    100.  
    101. void FindDialog::enableFindButton(const QString &text)
    102. {
    103. findButton->setEnabled(!text.isEmpty());
    104. }
    105. //*****************************************************
    106. //main.cpp file
    107.  
    108. #include<QApplication>
    109. #include "finddialog.h"
    110.  
    111. int main(int argc,char *argv[])
    112. {
    113. QApplication app(argc,argv);
    114. FindDialog *dialog=new FindDialog;
    115. dialog->show();
    116. return app.exec();
    117. }
    118. //****************************
    119.  
    120. //subdialog.pro file
    121.  
    122. ######################################################################
    123. # Automatically generated by qmake (2.01a) Sat Oct 16 23:27:20 2010
    124. ######################################################################
    125.  
    126. TEMPLATE = app
    127. TARGET =
    128. DEPENDPATH += .
    129. INCLUDEPATH += .
    130.  
    131. # Input
    132. HEADERS += finddialog.h
    133. SOURCES += finddialog.cpp main.cpp
    134. //*********************
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: compiled successfully but form is not displayed

    Here's your problem:
    Qt Code:
    1. setFixedHeight(sizeHint().height());
    To copy to clipboard, switch view to plain text mode 

    Print out the value of sizeHint().height() and see why it fails.

  3. #3
    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: compiled successfully but form is not displayed

    I compiled your project and it shows nothing because it crashes!
    And I think that this might be because of this line:
    Qt Code:
    1. rightLayout->addLayout(rightLayout);
    To copy to clipboard, switch view to plain text mode 
    I can't imagine what it might do :P
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  4. #4
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: compiled successfully but form is not displayed

    Change this

    Quote Originally Posted by zubair View Post
    rightLayout->addLayout(leftLayout);
    rightLayout->addLayout(rightLayout);
    to this

    mainLayout->addLayout ( leftLayout );
    mainLayout->addLayout ( rightLayout );
    and it should work ...

  5. #5
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: compiled successfully but form is not displayed

    thanks a lot..... faldzip !!
    now i know it was a silly mistake and nothing......

Similar Threads

  1. Replies: 3
    Last Post: 20th September 2010, 22:36
  2. Best way to check if file is successfully sent over QTcpSocket
    By cutie.monkey in forum Qt Programming
    Replies: 5
    Last Post: 17th October 2009, 20:24
  3. Unable to successfully create Qt application
    By remy06 in forum Qt Programming
    Replies: 1
    Last Post: 25th April 2009, 13:51
  4. Replies: 3
    Last Post: 4th February 2009, 16:52
  5. Form not displayed in QT Designer 4
    By demorphica in forum Qt Tools
    Replies: 2
    Last Post: 15th July 2008, 00:34

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.