diff --git a/protoDebuger/CMakeLists.txt b/protoDebuger/CMakeLists.txt index 6b12100..ac17a1a 100644 --- a/protoDebuger/CMakeLists.txt +++ b/protoDebuger/CMakeLists.txt @@ -55,7 +55,6 @@ set (UIS ) include(D:\\project\\c++qt\\qsswraper\\CMakeLists.txt) -include(D:\\project\\c++qt\\qsswraper\\extserial\\src\\qextserialport.cmake) QT5_WRAP_CPP(MOC ${SOURCES} ) # moc预编译代码 QT5_WRAP_CPP(MOCHEADER ${HEADERS} ) # moc预编译代码 @@ -86,6 +85,7 @@ target_compile_definitions(protoDebuger PRIVATE $<$,$>:QT_QML_DEBUG>) find_package( Qt5SerialPort) +find_package( Qt5QuickWidgets) target_link_libraries(protoDebuger - PRIVATE Qt5::Core Qt5::Quick Qt5::Widgets Qt5::SerialPort Qt5::Network) # 指定引入的QT功能,和qmake .pro 文件中的QT+= XXX类似 + PRIVATE Qt5::Core Qt5::Quick Qt5::Widgets Qt5::SerialPort Qt5::Network Qt5::QuickWidgets) diff --git a/protoDebuger/NetSelect.qml b/protoDebuger/NetSelect.qml index 2294c71..15a18a4 100644 --- a/protoDebuger/NetSelect.qml +++ b/protoDebuger/NetSelect.qml @@ -56,11 +56,12 @@ Item { font.bold: true Layout.columnSpan: 2 Layout.preferredHeight: 33 - Layout.preferredWidth: 233 + Layout.preferredWidth: 50 selectionColor: "#f0f0f1" cursorVisible: true font.pixelSize: 20 } + RadioButton { id: radioButton Layout.leftMargin: 20 diff --git a/protoDebuger/main.cpp b/protoDebuger/main.cpp index f8ed932..8707594 100644 --- a/protoDebuger/main.cpp +++ b/protoDebuger/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -16,24 +17,27 @@ ShareData gGlobal; -void RegisterQmlType(){ - qmlRegisterSingletonInstance("ShareData", 1, 0, "DataWrap",&gGlobal); -} int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QGuiApplication app(argc, argv); - SerialController *pSerial = new SerialController(); - QQuickView view; + QApplication app(argc, argv); - view.setResizeMode(QQuickView::SizeRootObjectToView); - view.setSource(QUrl("qrc:/main.qml")); - view.setTitle ("多用途通信协议调试器,基于lua"); - view.rootContext()->setContextProperty("DataWrap",&gGlobal); +// QQuickView view; +// view.setResizeMode(QQuickView::SizeRootObjectToView); +// view.setSource(QUrl("qrc:/main.qml")); +// view.setTitle ("多用途通信协议调试器,基于lua"); +// view.rootContext()->setContextProperty("DataWrap",&gGlobal); +// view.show(); + + QQuickWidget *m_quickWidget=new QQuickWidget(); + QUrl source("qrc:/main.qml"); + m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView ); + m_quickWidget->setSource(source); + m_quickWidget->rootContext()->setContextProperty("DataWrap",&gGlobal); + m_quickWidget->show(); + gGlobal.SetQuickView(m_quickWidget); - view.show(); - gGlobal.SetQuickView(&view); return app.exec(); } diff --git a/protoDebuger/main.qml b/protoDebuger/main.qml index fa366fc..385614f 100644 --- a/protoDebuger/main.qml +++ b/protoDebuger/main.qml @@ -5,12 +5,12 @@ import QtQuick.Controls 2.14 import QtQuick.Layouts 1.12 Rectangle { + objectName: "main" id: root - width: 800 - height: 600 + width: 1440 + height: 900 visible: true - Flow{ anchors.fill: parent width: parent.width diff --git a/protoDebuger/sharedata.cpp b/protoDebuger/sharedata.cpp index c79a461..87eb5a2 100644 --- a/protoDebuger/sharedata.cpp +++ b/protoDebuger/sharedata.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include ShareData::ShareData(QObject *parent) : QObject(parent), m_qml_view_(nullptr), @@ -24,22 +26,22 @@ ShareData::ShareData(QObject *parent) : QObject(parent), } } -int ShareData::SetQuickView(QQuickView *view) +int ShareData::SetQuickView(QQuickWidget *view) { QStringList comList; const auto infos = QSerialPortInfo::availablePorts(); for (const QSerialPortInfo &info : infos) { comList<m_qml_view_ = view; - QObject *qmlObject = view->findChild("SerialSelect", + QObject *qmlObject = view->rootObject()->findChild("SerialSelect", Qt::FindChildOption::FindChildrenRecursively); if(nullptr != qmlObject) qmlObject->setProperty("comlist",comList); - m_qml_protodebug_ = view->findChild("ProtoDebug", + m_qml_protodebug_ = view->rootObject()->findChild("ProtoDebug", Qt::FindChildOption::FindChildrenRecursively); + if(nullptr != m_qml_protodebug_) m_qml_protodebug_->setProperty("lua_script_text",m_lua_string); diff --git a/protoDebuger/sharedata.h b/protoDebuger/sharedata.h index d1e66ac..ca241d3 100644 --- a/protoDebuger/sharedata.h +++ b/protoDebuger/sharedata.h @@ -7,7 +7,7 @@ #include #include #include "lua_wraper.h" -#include +#include class ShareData; @@ -20,7 +20,7 @@ class ShareData : public QObject ,SerialController::SerialListener Q_PROPERTY(QString _txt READ rtxt WRITE settxt NOTIFY txtchanged) public: explicit ShareData(QObject *parent = nullptr); - int SetQuickView(QQuickView *); + int SetQuickView(QQuickWidget *); QString rtxt() const{ return _txt; } @@ -61,7 +61,7 @@ private: QObject *m_root_obj_; bool m_luavm_status_; QString m_lua_string; - QQuickView *m_qml_view_; + QQuickWidget *m_qml_view_; };