概述
#define qApp QCoreApplication::instance()
class Q_CORE_EXPORT QCoreApplication
#ifndef QT_NO_QOBJECT
: public QObject
#endif
class Q_GUI_EXPORT QGuiApplication : public QCoreApplication;
一个程序中只能有一个QCoreApplication及其子类的对象,该类主要提供无GUI程序的事件循环。QGuiApplication用于管理GUI程序的控制流和主要设置。
QApplication类
专门为QGuiApplication提供基于QWidget的程序所需的一些功能,主要用于处理部件的初始化、最终化,主要职责如下:
- 使用用户的桌面设置初始化应用程序。
- 执行事件处理,也就是说该类能从底层系统接收并分发事件。比如,使用QCoreApplication::sendEvent()或QCoreApplication::postEvent()函数分发自定义事件。
- 解析常用命令行参数并设置其内部状态。
- 定义了应用程序的界面外观,可使用QApplication::setStyle()进行更改。
- 指定应用程序如何分配颜色。
- 使用QCoreApplication::translate()函数对字符串进行转换。
- 通过QApplication::desktop()函数处理桌面,通过QCoreApplication::clipboard()函数处理剪贴板。
- 管理应用程序的鼠标光标。比如使用 QGuiApplication::setOverrideCuresor()函数设置光标等。
/*!
This method can be used to ensure leave and enter events are both in queue when moving from
one QWindow to another. This allows QWindow subclasses to check for a queued enter event
when handling the leave event (c QWindowSystemInterfacePrivate::peekWindowSystemEvent) to
determine where mouse went and act accordingly. E.g. QWidgetWindow needs to know if mouse
cursor moves between windows in same window hierarchy.
*/
void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local, const QPointF& global)
{
bool wasSynchronous = QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents;
if (wasSynchronous)
setSynchronousWindowsSystemEvents(false);
handleLeaveEvent(leave);
handleEnterEvent(enter, local, global);
if (wasSynchronous) {
flushWindowSystemEvents();
setSynchronousWindowsSystemEvents(true);
}
}
/*!
class QWindowSystemInterface
since 5.0
internal
preliminary
ingroup qpa
brief The QWindowSystemInterface provides an event queue for the QPA platform.
The platform plugins call the various functions to notify about events. The events are queued
until sendWindowSystemEvents() is called by the event dispatcher.
*/
void QWindowSystemInterface::handleEnterEvent(QWindow *tlw, const QPointF &local, const QPointF &global)
{
if (tlw) {
QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(tlw, local, global);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
}
void QWindowSystemInterfacePrivate::handleWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *ev)
{
if (synchronousWindowsSystemEvents) {
QGuiApplicationPrivate::processWindowSystemEvent(ev);
} else {
windowSystemEventQueue.append(ev);
QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher();
if (dispatcher)
dispatcher->wakeUp();
}
}
void QWindowSystemInterface::handleMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b,
Qt::KeyboardModifiers mods, Qt::MouseEventSource source)
{
QWindowSystemInterfacePrivate::MouseEvent * e =
new QWindowSystemInterfacePrivate::MouseEvent(w, timestamp, local, global, b, mods, source);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
最后
以上就是陶醉故事为你收集整理的QT(3)——Application spontaneous底层的窗口系统的全部内容,希望文章能够帮你解决QT(3)——Application spontaneous底层的窗口系统所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复