PDA

View Full Version : compiled successfully but form is not displayed



zubair
16th October 2010, 19:16
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....



//finddialog.h file

#ifndef FINDDIALOG_H
#define FINDDIALOG_H

#include<QDialog>

class QLineEdit;
class QCheckBox;
class QLabel;
class QPushButton;

class FindDialog:public QDialog
{
Q_OBJECT
public:
FindDialog(QWidget *parent=0);

signals:
void findNext(const QString &str,Qt::CaseSensitivity cs);
void findPrevious(const QString &str,Qt::CaseSensitivity cs);

public slots:
void findClicked();
void enableFindButton(const QString &text);

private:
QLabel *label;
QLineEdit *lineEdit;
QCheckBox *caseCheckBox;
QCheckBox *backwardCheckBox;
QPushButton *findButton;
QPushButton *closeButton;
};
#endif
//************************************************
//finddialog.cpp
#include<QtGui>
#include "finddialog.h"

FindDialog::FindDialog(QWidget *parent):QDialog(parent)
{
label=new QLabel("Find &what: ");
lineEdit=new QLineEdit;
label->setBuddy(lineEdit);

caseCheckBox=new QCheckBox("Match &case");
backwardCheckBox=new QCheckBox("Search &backward");

findButton=new QPushButton("&Find");
findButton->setDefault(true);
findButton->setEnabled(false);

closeButton=new QPushButton("Close");

connect(lineEdit,SIGNAL(textChanged(const QString &)),
this,SLOT(enableFindButton(const QString &)));
connect(findButton,SIGNAL(clicked()),
this,SLOT(findClicked()));
connect(closeButton,SIGNAL(clicked()),
this,SLOT(close()));

QHBoxLayout *topleftLayout=new QHBoxLayout;
topleftLayout->addWidget(label);
topleftLayout->addWidget(lineEdit);

QVBoxLayout *leftLayout=new QVBoxLayout;
leftLayout->addLayout(topleftLayout);
leftLayout->addWidget(caseCheckBox);
leftLayout->addWidget(backwardCheckBox);

QVBoxLayout *rightLayout=new QVBoxLayout;
rightLayout->addWidget(findButton);
rightLayout->addWidget(closeButton);
rightLayout->addStretch();

QHBoxLayout *mainLayout=new QHBoxLayout;
rightLayout->addLayout(leftLayout);
rightLayout->addLayout(rightLayout);
setLayout(mainLayout);

setWindowTitle("Find");
setFixedHeight(sizeHint().height());
}

void FindDialog::findClicked()
{
QString text=lineEdit->text();
Qt::CaseSensitivity cs=caseCheckBox->isChecked()?
Qt::CaseSensitive:Qt::CaseInsensitive;

if(backwardCheckBox->isChecked())
{
emit findPrevious(text,cs);
}
else
{
emit findNext(text,cs);
}
}

void FindDialog::enableFindButton(const QString &text)
{
findButton->setEnabled(!text.isEmpty());
}
//************************************************** ***
//main.cpp file

#include<QApplication>
#include "finddialog.h"

int main(int argc,char *argv[])
{
QApplication app(argc,argv);
FindDialog *dialog=new FindDialog;
dialog->show();
return app.exec();
}
//****************************

//subdialog.pro file

################################################## ####################
# Automatically generated by qmake (2.01a) Sat Oct 16 23:27:20 2010
################################################## ####################

TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += finddialog.h
SOURCES += finddialog.cpp main.cpp
//*********************

tbscope
16th October 2010, 19:22
Here's your problem:

setFixedHeight(sizeHint().height());

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

faldzip
16th October 2010, 19:33
I compiled your project and it shows nothing because it crashes!
And I think that this might be because of this line:


rightLayout->addLayout(rightLayout);

I can't imagine what it might do :P

gboelter
17th October 2010, 06:20
Change this



rightLayout->addLayout(leftLayout);
rightLayout->addLayout(rightLayout);


to this



mainLayout->addLayout ( leftLayout );
mainLayout->addLayout ( rightLayout );


and it should work ...

zubair
17th October 2010, 15:39
thanks a lot..... faldzip !!
now i know it was a silly mistake and nothing......:):):)