Qt4读书笔记15

 

多文档(Multiple Documents)

 

#include <QApplication>

#include "mainwindow.h"

 

int main(int argc, char *argv[])

{

       QApplication app(argc, argv);

       MainWindow mainWin;

       mainWin.show();

       return app.exec();

}

 

这次创建MainWindow没有使用new .函数结束时MainWindow对象会自动销毁。

 

如果改为多窗口程序:

int main(int argc, char *argv[])

{

       QApplication app(argc, argv);

       MainWindow *mainWin = new MainWindow;

       mainWin->show();

       return app.exec();

}

 

File|new修改:

void MainWindow::newFile()

{

       MainWindow *mainWin = new MainWindow;

       mainWin->show();

}

 

奇怪的是我们没有保存window的指针,这没有什么问题,Qt保留了;

 

void MainWindow::createActions()

{

       ...

       closeAction = new QAction(tr("&Close"), this);

       closeAction->setShortcut(QKeySequence::Close);

       closeAction->setStatusTip(tr("Close this window"));

       connect(closeAction, SIGNAL(trigged()), this, SLOT(close()));

 

       exitAction = new QAction(tr("E&xit"), this);

       exitAction->setSHortcut(tr("Ctrl+Q"));

       exitAction->setStatusTip(tr("Exit the application"));

       connect(exitAction, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));

       ...

}

 

启动界面(splash screens)

许多应用在启动是呈现一个启动界面。一些开发者使用启动界面装饰缓慢的启动,或者是市场部门满意。在Qt应用中增加启动界面是很容易的。

 

使用的类为QSplashScreen. QSplashScreen类显示在main window前。能够在image上写一些信息来通知用户当前的进度。

 

int main(int argc, char *argv[])

{

       QApplication app(argc, argv);

 

       QSplashScreen *splash = new QSplashScreen;

       splash->setPixmap(QPixmap(":/images/splash.png"));

       splash->show();

 

       Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;

       splash->showMessage(QObject::tr("Setting up the main window..."), topRight, Qt::white);

      

       MainWindow mainWin; 

 

       splash->showMessage(QObject::tr("Loading modules..."), topRight, Qt::white);

 

       loadModules();

 

       splash->showMessage(QObject::tr("Establishing connections..."), topRight, Qt::white);

       establishConnections();

 

       mainWin.show();

       splash->finish(&mainWin);

       delete splash;

 

       return app.exec();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值