Chinaunix首页 | 论坛 | 博客
  • 博客访问: 45225
  • 博文数量: 12
  • 博客积分: 325
  • 博客等级: 一等列兵
  • 技术积分: 170
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-02 12:08
文章分类

全部博文(12)

文章存档

2012年(12)

我的朋友

分类: LINUX

2012-09-20 10:16:27

stringdlg.h

点击(此处)折叠或打开

  1. #ifndef DLGSTR_H
  2. #define DLGSTR_H
  3. #include <QDialog>
  4. class QString;
  5. class QPushButton;
  6. class QLineEdit;
  7. class QTextEdit;
  8. class QString;
  9. class DlgStr:public QDialog
  10. {
  11.     Q_OBJECT
  12. public:
  13.     DlgStr(QWidget *parent = 0);
  14. public slots:
  15.     void slot_show_txt();
  16. private:
  17.     QPushButton *btnOk;
  18.     QLineEdit *lineEdit;
  19.     QTextEdit *txtEdit;
  20.     QString str;

  21. };


  22. #endif // DLGSTR_H

stringdlg.cpp

点击(此处)折叠或打开

  1. #include <QPushButton>
  2. #include <QLineEdit>
  3. #include <QTextEdit>
  4. #include <QString>
  5. #include <QTextStream>
  6. #include <QVBoxLayout>
  7. #include "dlgstr.h"

  8. DlgStr::DlgStr(QWidget *parent):QDialog(parent)
  9. {
  10.     btnOk = new QPushButton("OK");
  11.     lineEdit = new QLineEdit;
  12.     txtEdit = new QTextEdit;

  13.     QVBoxLayout *layout = new QVBoxLayout;
  14.     layout->addWidget(lineEdit);
  15.     layout->addWidget(txtEdit);
  16.     layout->addWidget(btnOk);
  17.     setLayout(layout);
  18.     connect(btnOk,SIGNAL(clicked()),this, SLOT(slot_show_txt()));

  19. }

  20. void DlgStr::slot_show_txt()
  21. {
  22.     txtEdit->setText(lineEdit->text());
  23.     QTextStream cout(stdout);
  24.     cout <<"you input txt " <<lineEdit->text() << endl;
  25. }


main.cpp

点击(此处)折叠或打开

  1. #include <QApplication>
  2. #include "dlgstr.h"

  3. int main(int argc, char** argv)
  4. {
  5.     QApplication app(argc, argv);
  6.     DlgStr *dlg = new DlgStr;
  7.     dlg->show();
  8.     return app.exec();
  9. }



 

 

 

 

image

image

阅读(1007) | 评论(0) | 转发(0) |
0

上一篇:[Qt练习]QMainWindow

下一篇:[Qt]标准对话框

给主人留下些什么吧!~~