Qt入门-应用程序类QApplication

QApplication类:

[cpp]  view plain  copy
  1. class Q_GUI_EXPORT QApplication : public QCoreApplication  
  2. {  
  3.     Q_OBJECT  
  4.     ...  


QApplication是应用程序管理类。它包含应用程序资源管理、消息处理机制等。

常用的几个方法:

(1) int QCoreApplication::exec ():启动程序,进入消息循环;

(2) QCoreApplication::exit ( int returnCode = 0 ):终止消息循环,退出程序;

(3) QString QCoreApplication::applicationDirPath ():返回应用程序的路径,不包含最后的“\”;

(4) void QCoreApplication::addLibraryPath ( const QString & path ):设置一个库的优先搜索路径;

(5) QString QCoreApplication::applicationFilePath ():返回应用程序的全路径名;

(6) qint64 QCoreApplication::applicationPid ():返回应用程序的进程ID;

(7) void QCoreApplication::postEvent ( QObject * receiver, QEvent * event ):将事件发送到队列并立即返回;

(8) bool QCoreApplication::sendEvent ( QObject * receiver, QEvent * event ):发送事件到队列,并等待返回结果;

     示例:

[cpp]  view plain  copy
  1. QMouseEvent event(QEvent::MouseButtonPress, pos, 0, 0, 0);  
  2. QApplication::sendEvent(mainWindow, &event);  

 

(9) void QCoreApplication::sendPostedEvents ( QObject * receiver, int event_type ):立即分派事件队列中先前由portEevent发送的事件;

(10) void QCoreApplication::processEvents ( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ):立即分派事件队列中flags指定的事件,直到没有事件可处理;

(11) QString QCoreApplication::translate ( const char * context, const char * sourceText, const char * disambiguation, Encoding encoding, Encoding encoding = CodecForTr ):通过查询安装的消息文件,返回sourceText的翻译文本,如果安装文件不包含它则返回“sourceText”。context通常是一个类名(例如,“MyDialog”)并且sourceText是英语文本或者一个短的标识文本,如果输出文本很长可以通过一个短的名称查找到一个长的名称(就像帮助文本那样的)。这个有些类似VC下的LoadString。

     参考:QObject::tr() and QObject::trUtf8()

     示例:QApplication::translate("qt_appClass", "qt_app", 0, QApplication::UnicodeUTF8)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值