Chinaunix首页 | 论坛 | 博客
  • 博客访问: 105548
  • 博文数量: 10
  • 博客积分: 530
  • 博客等级: 中士
  • 技术积分: 110
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-06 15:24
文章分类

全部博文(10)

文章存档

2008年(10)

我的朋友

分类: LINUX

2008-05-16 10:58:12

//qt单窗体程序全界面创建过程
1、建立工程文件(hello.pro)
新建终端,
#designer
New File/Project:C++ Project:OK
Project File:hello.pro:OK
2、建立窗体文件(hello_form.ui)
File->New:Dialog/Widget:OK
属性:name:Hello_Form
      caption:Hello
部件:textlabel:name:textlabel_Hello
                text:Hello World!
      pushButton:name:pushButton_quit
                 text:quit
          右键属性中:Connections:
          sender:pushButton_quit
                 signal:clicked()
                 receiver:Hello_Form
                 Slot:reject()
注:也可以先建立窗体文件(.ui),然后打开工程文件(.pro),菜单Project->Add File
3、建立main.cpp
File->New:C++ Main-File(main.cpp):OK
4、建立Makefile
#qmake -o Makefile hello.pro
注:Makefile除了可以用qmake产生外,还可以用configure产生
5、建立工程可执行文件
#make
过程:uic hello_form.ui -o hello_form.h
      g++ -o main.o main.cpp
      uic hello_form.ui hello_form.h -o hello_form.cpp
      g++ -o hello_form.o hello_form.cpp
      moc hello_form.h -o moc_hello_form.cpp
      g++ -o moc_hello_form.o moc_hello_form.cpp
     
      g++ -o hello main.o hello_form.o moc_hello_form.o
6、运行
#hello

//以下在上面单窗体程序基础上增加一个窗体,实现多窗体之间的按钮切换操作
7、建立新的窗体文件(hello_echo_form.ui)
File->New:Dialog/Widget:OK
属性:name:Hello_echo_Form
      caption:HelloEcho
部件:textlabel:name:textlabel_Hello
                text:Hello World!
      pushButton:name:pushButton_quit
                 text:quit
          右键属性中:Connections:
          sender:pushButton_quit
                 signal:clicked()
                 receiver:Hello_Form
                 Slot:reject()
打开工程(hello.pro),从菜单中选择加入新的窗体文件(hello_echo_form.ui)
8、打开主窗体文件(hello_form.ui)
在窗体上增加按钮 pushButton:name:hello_send
                 text:hellosend
          右键属性中:Connections:
          sender:hello_send
                 signal:clicked()
                 receiver:Hello_Form
                 Slot:hello_send_click()//新建
双击主窗体文件,新建或打开hello_form.ui.h文件
内容:
#include "hello_echo_form.h"
void Hello_Form::hello_send_click()
{
    Hello_echo_Form a(this);
    a.exec();
}
9、打开main.cpp文件
增加:
#include "hello_echo_form.h"
10、#make
11、#hello
注:qt支持多线程,Makefile中需要有-DQT_THREAD_SUPPORT,-lqt-mt选项
阅读(4568) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~