• 5368阅读
  • 2回复

为啥第二章的第一个例子我在windows下编译执行没反映呢??? [复制链接]

上一主题 下一主题
离线yarco
 

只看楼主 倒序阅读 楼主  发表于: 2009-03-19
为啥第二章的第一个例子我在windows下编译执行没反映呢???
finddialog.h
  1. #ifndef FINDDIALOG_H
  2. #define FINDDIALOG_H
  3. #include <QDialog>
  4. class QLabel;
  5. class QLineEdit;
  6. class QCheckBox;
  7. class QPushButton;
  8. class FindDialog : public QDialog
  9. {
  10.     Q_OBJECT
  11. public:
  12.     FindDialog(QWidget* parent = 0);
  13. signals:
  14.     void findNext(const QString& str, Qt::CaseSensitivity cs);
  15.     void findPrevious(const QString& str, Qt::CaseSensitivity cs);
  16. private slots:
  17.     void findClicked();
  18.     void enableFindButton(const QString& str);
  19. private:
  20.     QLabel* label;
  21.     QLineEdit* lineEdit;
  22.     QCheckBox* caseCheckBox;
  23.     QCheckBox* backwardCheckBox;
  24.     QPushButton* findButton;
  25.     QPushButton* closeButton;
  26. };
  27. #endif


finddialog.cpp
  1. #include <QtGui>
  2. #include "finddialog.h"
  3. FindDialog::FindDialog(QWidget* parent)
  4.     : QDialog(parent)
  5. {
  6.     label = new QLabel(tr("Find &what:"));
  7.     lineEdit = new QLineEdit;
  8.     label->setBuddy(lineEdit);
  9.     caseCheckBox = new QCheckBox(tr("Match &case"));
  10.     backwardCheckBox = new QCheckBox(tr("Search &backward"));
  11.     findButton = new QPushButton(tr("&Find"));
  12.     findButton->setDefault(true);
  13.     findButton->setEnabled(false);
  14.     closeButton = new QPushButton(tr("Close"));
  15.     connect(lineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(enableFindButton(const QString &)));
  16.     connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
  17.     connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
  18.     QHBoxLayout* topLeftLayout = new QHBoxLayout;
  19.     topLeftLayout->addWidget(label);
  20.     topLeftLayout->addWidget(lineEdit);
  21.     QVBoxLayout* leftLayout = new QVBoxLayout;
  22.     leftLayout->addLayout(topLeftLayout);
  23.     leftLayout->addWidget(caseCheckBox);
  24.     leftLayout->addWidget(backwardCheckBox);
  25.     QVBoxLayout* rightLayout = new QVBoxLayout;
  26.     rightLayout->addWidget(findButton);
  27.     rightLayout->addWidget(closeButton);
  28.     rightLayout->addStretch();
  29.     QHBoxLayout* mainLayout = new QHBoxLayout;
  30.     mainLayout->addLayout(leftLayout);
  31.     mainLayout->addLayout(rightLayout);
  32.     setWindowTitle(tr("Find"));
  33.     setFixedHeight(sizeHint().height());
  34. }
  35. void FindDialog::findClicked()
  36. {
  37.     QString text = lineEdit->text();
  38.     Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
  39.     if (backwardCheckBox->isChecked())
  40.     {
  41.         emit findPrevious(text, cs);
  42.     }
  43.     else
  44.     {
  45.         emit findNext(text, cs);
  46.     }
  47. }
  48. void FindDialog::enableFindButton(const QString& str)
  49. {
  50.     findButton->setEnabled(str.isEmpty());
  51. }


qt_2_dialog.cpp
  1. // qt_2_dialog.cpp : 定义控制台应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include <QApplication>
  5. #include "finddialog.h"
  6. int _tmain(int argc, _TCHAR* argv[])
  7. {
  8.     QApplication app(argc, argv);
  9.     FindDialog* dialog = new FindDialog;
  10.     dialog->show();
  11.     return app.exec();
  12. }


各位给看看, 应该和书里的一样的啊....
我一编译, 一执行没任何反应...查看进程会有个僵尸进程...
咋回事呢?

另, 象这种情况我如何调试呢?
离线yarco

只看该作者 1楼 发表于: 2009-03-19
我好强啊....这是我的第一个帖子...
各位给点面子啊


忘了说了:
系统环境 windows vista home basic
qt库: 4.4.3 opensource
编译环境: visual studio 2008 c++ express
[ 此帖被yarco在2009-03-19 22:37重新编辑 ]
离线yarco

只看该作者 2楼 发表于: 2009-03-20
找到了...偶下载了原书的代码一比对...原来少了

setLayout(mainLayout);

// finddialog.cpp
快速回复
限100 字节
 
上一个 下一个