Chinaunix首页 | 论坛 | 博客
  • 博客访问: 515696
  • 博文数量: 174
  • 博客积分: 8001
  • 博客等级: 中将
  • 技术积分: 1840
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-04 19:30
文章分类

全部博文(174)

文章存档

2011年(1)

2010年(24)

2009年(149)

我的朋友

分类: LINUX

2009-05-25 18:31:17

使用的是Qt designer1.1,虽然是落后很多的版本了。但是要配合开发板。这个版本和2.0的版本的不同,首先是没有C++ project之类的。也就是说,代码还是用vim写,但是界面可以用这个设计。这样也没有什么不习惯的地方。
关于教程,网上找到的都是2.0之后的版本的。好在Qt的文档还是挺丰富的,trolltech公司还是提供了很好的在线文档。那就没什么问题了。
PS:程序运行的时候出现:
Xlib: extension "RENDER" missing on display ":0.0"
查了一下可能是显卡问题或者XFree的问题,这样透明化或者字体反色的效果就不能用了。由于都说不影响程序运行,就先不打算解决了。
Tutorial: The 14 Steps
14步教程
It doesn't cover everything: The emphasis is on teaching the programming philosophy of GUI programming, and Qt's features are introduced as needed. Some commonly used features are never used in this tutorial.
Chapter 1: Hello, World!
A widget is a user interface object which can process user input and draw graphics. The programmer can change both the overall look and feel and many minor properties of it such as color, as well as the widget's content.
QPushButton ( const QString & text, QWidget * parent, const char * name=0 ) 
 
name是内部标识名。可以用来查找特定的QObject.
Chapter 2: Calling it Quits
QObject::connect( &quit, SIGNAL(clicked()), &a, SLOT(quit()) );

connect() is perhaps the most central feature of Qt. Note that connect() is a static function in QObject. Do not confuse it with the connect() function in the socket library. This line establishes a one-way connection between two Qt objects (objects that inherit QObject, directly or indirectly). Every Qt object can have both signals (to send messages) and slots (to receive messages). All widgets are Qt objects. They inherit QWidget which in turn inherits QObject. Here, the clicked() signal of quit is connected to the quit() slot of a, so that when the button is clicked, the application quits.

 

Chapter 3: Family Values
 

#include <qapplication.h>
#include <qpushbutton.h>
#include <qfont.h>

class MyWidget : public QWidget
{
public:
    MyWidget( QWidget *parent=0, const char *name=0 );
};

MyWidget::MyWidget( QWidget *parent, const char *name )
        : QWidget( parent, name )
{
    setMinimumSize( 200, 120 );
    setMaximumSize( 200, 120 );

    QPushButton *quit = new QPushButton( "Quit", this, "quit" );
    quit->setGeometry( 62, 40, 75, 30 );
    quit->setFont( QFont( "Times", 18, QFont::Bold ) );

    connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
}

int main( int argc, char **argv )
{
    QApplication a( argc, argv );

    MyWidget w;
    w.setGeometry( 100, 100, 200, 120 );
    a.setMainWidget( &w );
    w.show();
    return a.exec();
}

注意到在MyWidget的构造函数里,quit的实例是有Qt管理,在生命周期结束时释放。所以这里没有析构函数。(你也可以手动添加析构函数来释放它)

 

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