Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4242260
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: C/C++

2011-04-23 16:39:28


本文记录了qt creator 的一些简单的使用方法。本篇中,我

们通过两钟代码实现  信号槽 功能实现



我们接着 “qt creator 信号与槽 ui 实现” 第八步


一、通过 go to  slot 选项实现

1.单击 “今天”,选择 go to slots

2.在 mianwindow.h 文件下产生了
    
  1. private slots:
  2.     void on_todayButton_clicked();

3.在 mianwindow.cpp 文件产生了
  1. void MainWindow::on_todayButton_clicked()
  2. {
  3.    
  4. }

4.我们在 上述文件中添加为如下,也是显示 下一个月的功能
  1. void MainWindow::on_todayButton_clicked()
  2. {
  3.     ui->calendarWidget->showNextMonth();
  4. }
5.我们通过ui 界面设置 “close”  信号槽 功能

6.编译,运行 和 上一篇 一样,实现了相同的功能

***********************************************************************


二.通过 自己代码实现
 

1.在mianwindow.h中 添加自己

  1. private:
  2.     Ui::MainWindow *ui;

  3. private slots:
  4.     void on_todayButton_clicked();
  5.     void gototoday();  //自己添加槽函数
  6. };

2.在 mainwindow.cpp中实现 gototoday()


  1. void MainWindow::on_todayButton_clicked()
  2. {
  3.   // ui->calendarWidget->showNextMonth();
  4. }

  5. void MainWindow::gototoday()   实现 gototoday 函数
  6. {
  7.     ui->calendarWidget->showNextMonth();
  8. }

3.mainwindow.cpp 的构造函数中添加 connect 连接函数


  1. MainWindow::MainWindow(QWidget *parent) :
  2.     QMainWindow(parent),
  3.     ui(new Ui::MainWindow)
  4. {
  5.     ui->setupUi(this);   //添加代码 红色
  6.     connect(ui->todayButton,SIGNAL(clicked()),this,SLOT(gototoday()));
  7. }

4. qmake 

同样实现一样的功能




阅读(2114) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~