Posted on 2011-09-15 21:25
RTY 閱讀(761)
評(píng)論(0) 編輯 收藏 引用 所屬分類(lèi):
Qt
注:本文內(nèi)容基于現(xiàn)階段的Qt5源碼,等Qt5正式發(fā)布時(shí),本文的內(nèi)容可能不再適用了。 2011.09.11
QPA插件加載
Qt5所有的gui程序都將依賴(lài)一個(gè) qpa 插件(QGuiApplication初始化時(shí)將會(huì)加載qpa插件)。
- 程序如何知道去哪兒找插件呢?
- 又如何知道加載哪一個(gè)插件呢?
路徑
命令行參數(shù):-platformpluginpath
環(huán)境變量: QT_QPA_PLATFORM_PLUGIN_PATH
常規(guī)插件路徑(QCoreApplication::libraryPaths())下的platform子目錄
插件名
QWindow
QWidget和QApplication都從QtGui模塊中移走了(移到了QtWidgets模塊)。那么如何使用QtGui模塊寫(xiě)一個(gè)最簡(jiǎn)單的界面呢?
需要使用 QWindow 和 QGuiApplication,一個(gè)簡(jiǎn)單的例子:
#ifndef WINDOW_H
#define WINDOW_H
#include <QtGui/QWindow>
class Window : public QWindow
{
Q_OBJECT
public:
Window(QWindow *parent = 0);
protected:
void exposeEvent(QExposeEvent *);
void resizeEvent(QResizeEvent *);
private:
void render();
QBackingStore *m_backingStore;
};
#endif // WINDOW_H
#include "window.h"
#include <QtGui/QPainter>
#include <QtGui/QBackingStore>
Window::Window(QWindow *parent)
: QWindow(parent)
{
setGeometry(QRect(10, 10, 640, 480));
m_backingStore = new QBackingStore(this);
}
void Window::exposeEvent(QExposeEvent *)
{
render();
}
void Window::resizeEvent(QResizeEvent *)
{
render();
}
void Window::render()
{
QRect rect(QPoint(), geometry().size());
m_backingStore->resize(rect.size());
m_backingStore->beginPaint(rect);
QPainter p(m_backingStore->paintDevice());
p.drawRect(rect);
m_backingStore->endPaint();
m_backingStore->flush(rect);
}
#include <QtGui/QGuiApplication>
#include "window.h"
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
Window w;
w.show();
return a.exec();
}