我必须在具有最新 Qt 版本(Qt 5.2)的基于 Qml 的应用程序中重用 Widget 应用程序。但对于大多数人来说,这样做是非常糟糕的主意。
有人可以解释一下,为什么这是个坏主意?
一些代码片段,
*。H
class MyAppItem: public QQuickPaintedItem{
Q_OBJECT
public:
explicit MyAppItem(QQuickItem *parent = 0);
void paint(QPainter *painter);
private:
CMyAppWidget *bp;
};
class RouteBWExtensionPlugin: public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
/**
* @brief register the plugin
* @param[in] uri to be registered
*/
void registerTypes(const char * uri);
};
*.cpp
MyAppItem::MyAppItem(QQuickItem *parent)
: QQuickPaintedItem(parent)
{
bp = new CMyAppWidget();
}
void MyAppItem::paint(QPainter *painter)
{
bp->render(painter);
}
void RouteBWExtensionPlugin::registerTypes(const char * uri)
{
qmlRegisterType<MyAppItem>(uri, 1, 0, "MyAppItem");
}
*.qml 文件
import MyAppWidget 1.0
Item {
width: 300
height: 10
anchors.right: parent
MyAppItem {
width: 94
height: 240
anchors.right: parent
MouseArea{
anchors.fill: parent
onClicked: {
console.log("[veo] onClicked - capture triggered")
}
}
}
}