找回密码
 立即注册
收起左侧

QML Loader 信号槽无法传递参数问题?

4
回复
6650
查看
[复制链接]
累计签到:12 天
连续签到:1 天
来源: 2019-5-17 14:44:50 显示全部楼层 |阅读模式
10Qter豆
先上代码:
  1.             StackLayout {
  2.                 id: mainView;
  3.                 width: 600 * root.hRatio;
  4.                 height: 420 * root.vRatio;
  5.                 anchors.left: leftNav.right;

  6.                 Loader {
  7.                     id: home;
  8.                     source: "qrc:/Home.qml"
  9.                 }
  10.                 Loader {
  11.                     id: comConfig;
  12.                     source: "./ComConfig.qml";
  13.                 }
  14.                 Loader {
  15.                     id: modbusTest;
  16.                     source: "qrc:/ModbusTest.qml";
  17.                 }
  18.                 Loader {
  19.                     id: readCmd;
  20.                     source: "qrc:/ReadCmd.qml";
  21.                 }
  22.                 Loader {
  23.                     id: modifyCmd;
  24.                     source: "qrc:/ModifyCmd.qml";
  25.                 }
  26.             }
复制代码
ComConfig.qml 代码:
  1. import QtQuick 2.0
  2. import QtQuick.Controls 2.0
  3. import QtQuick.Layouts 1.4

  4. Rectangle {
  5.     id: comRect;
  6.     color: "transparent";

  7.     signal openModbus(string device, int baud);
  8.     signal close();

  9.     function openFb(result, baud, stopbits, parity, databits)
  10.     {
  11.         console.log(baud, stopbits, parity, databits);
  12.         if(result){
  13.             baudrate.text = baud.toString();
  14.             stop.text = stopbits.toString();
  15.             paritybits.text  = parity;
  16.             data.text = databits.toString();
  17.             openClose.text = "关闭";
  18.             comStatus.text = "串口状态: 已打开";
  19.         }else{
  20.             comStatus.text = "串口状态: 打开失败";
  21.         }
  22.     }

  23.     function closeFb()
  24.     {
  25.         openClose.text = "打开";
  26.         comStatus.text = "串口状态: ";
  27.         baudrate.text = "";
  28.         stop.text = "";
  29.         paritybits.text  = "";
  30.         data.text = "";
  31.     }

  32.     GridLayout {
  33.         rows: 5;
  34.         columns: 5;
  35.         rowSpacing: 10;
  36.         columnSpacing: 10;

  37.         ULabel {
  38.             text: "串口配置:";
  39.             Layout.row: 0; Layout.column: 0;
  40.             Layout.columnSpan: 2;
  41.             Layout.topMargin: 30;
  42.         }

  43.         ULabel {
  44.             Layout.row: 1; Layout.column: 0;
  45.             text: "串口号";
  46.         }
  47.         UComboBox {
  48.             Layout.row: 1; Layout.column: 1;
  49.             id: com;
  50.             implicitWidth: 100;
  51.             model: ["COM1", "COM2", "COM3",
  52.                 "COM4", "COM5", "COM6", "COM7",
  53.                 "COM8", "COM9", "COM10", "COM11"]
  54.         }

  55.         ULabel {
  56.             Layout.row: 2; Layout.column: 0;
  57.             text: "波特率"
  58.         }
  59.         UComboBox {
  60.             Layout.row: 2; Layout.column: 1;
  61.             id: baude;
  62.             model: [1200, 2400, 4800, 9600, 19200];
  63.             implicitWidth: 100;
  64.         }
  65.         UButton {
  66.             Layout.row: 4; Layout.column: 1;
  67.             id: openClose;
  68.             implicitWidth: 100;
  69.             text: "打开";
  70.             onClicked: {
  71.                 if(openClose.text == "打开"){
  72.                     var currentCom = com.currentText;
  73.                     var currentbaude = parseInt(baude.currentText);
  74.                     comRect.openModbus(currentCom, currentbaude);
  75.                 }else{
  76.                     comRect.close();
  77.                 }

  78.             }
  79.         }

  80.         // 占坑
  81.         ULabel {
  82.             width: 100;
  83.             Layout.row: 0; Layout.column: 2;
  84.         }


  85.         // 反馈的状态
  86.         ULabel {
  87.             id: comStatus;
  88.             text: "串口状态:";
  89.             Layout.topMargin: 30;
  90.             Layout.row: 0; Layout.column: 3;
  91.             Layout.columnSpan: 2;
  92.         }
  93.         ULabel {
  94.             Layout.row: 1; Layout.column: 3;
  95.             text: "波特率:";
  96.         }
  97.         ULabel{
  98.             id: baudrate;
  99.             Layout.row: 1; Layout.column: 4;
  100.         }

  101.         ULabel {
  102.             Layout.row: 2; Layout.column: 3;
  103.             text: "停止位:";
  104.         }
  105.         ULabel {
  106.             id: stop;
  107.             Layout.row: 2; Layout.column: 4;
  108.         }

  109.         ULabel {
  110.             Layout.row: 3; Layout.column: 3;
  111.             text: "校验位:";
  112.         }
  113.         ULabel {
  114.             id: paritybits;
  115.             Layout.row: 3; Layout.column: 4;
  116.         }

  117.         ULabel {
  118.             Layout.row: 4; Layout.column: 3;
  119.             text: "数据位:";
  120.         }
  121.         ULabel {
  122.             id: data;
  123.             Layout.row: 4; Layout.column: 4;
  124.         }
  125.     }
  126. }
复制代码
在qmlscene ./main.qml 的时候信号和槽能正常触发,也可以正常传递参数;但在编译调试模式下可以触发信号槽,但是在槽里面出现参数未定义. 调试结果:


附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册
回复

使用道具 举报

累计签到:12 天
连续签到:1 天
2019-5-17 14:47:44 显示全部楼层
本帖最后由 北辰 于 2019-5-17 17:50 编辑

补充main.qml 的代码


  1. import QtQuick 2.9
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 2.0
  4. import QtQuick.Layouts 1.4
  5. import an.qt.HandleHumiture 1.0

  6. ApplicationWindow {
  7.     id: root;
  8.     visible: true;
  9.     width: 960; height: 540;
  10.     property int _width: 960;
  11.     property int _height: 540;
  12.     property double hRatio: width / _width;
  13.     property double vRatio: height / _height;
  14.     // 去掉标题栏,自定义标题栏
  15.     flags: Qt.Window | Qt.FramelessWindowHint;

  16.     BorderImage {
  17.         id: name
  18.         source: "qrc:/image/background.jpg";
  19.         width: root.width; height: root.height;
  20.         border.left: 5; border.top: 5
  21.         border.right: 5; border.bottom: 5
  22.     }

  23.     // 处理 root 的鼠标动作
  24.     MouseArea {
  25.         id: rootMouseArea;
  26.         anchors.fill: parent;
  27.         acceptedButtons: Qt.LeftButton;
  28.         hoverEnabled: true;
  29.         /*
  30.             * 将界面分成一个九宫格分别为: LeftTop Top RightTop Left Center Right
  31.             * LeftBottom Bottom RightBottom, 鼠标在这九个区域内需要做特殊处理.
  32.             * 边界缩放范围 step = 5, 也就是说鼠标在四边 step 范围内且没有按住左键
  33.             * 的情况下,只改变鼠标形状,按住了左键然后移动鼠标,就需要处理缩放界面.
  34.             * 如果在边界缩放范围外,且在界面内任何主界面(非子控件),都正常显示鼠标
  35.             * 形状,如果按住左键并移动鼠标,则移动主界面,放开鼠标左键,则恢复鼠标形状
  36.             */
  37.         property point clickPos: "0,0"

  38.         // 边框缩放的范围
  39.         property int step: 10;
  40.         // 是否点击
  41.         property bool isClicked: false;
  42.         // 鼠标的状态
  43.         property int mouseState: 0
  44.         // 最小宽高
  45.         property int minWidthHeight:30;

  46.         onDoubleClicked: {
  47.             handleMaxButton();
  48.             isClicked = false;
  49.             mouse.accepted = true;
  50.         }

  51.         onPressed: {
  52.             focus = true;
  53.             isClicked = true;
  54.             clickPos = Qt.point(mouse.x, mouse.y)
  55.             mouse.accepted = true;
  56.         }
  57.         onReleased: {
  58.             isClicked = false;
  59.             mouse.accepted = true;
  60.         }

  61.         onPositionChanged: {
  62.             if(isClicked)
  63.             {
  64.                 //鼠标偏移量
  65.                 var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
  66.                 switch(mouseState){
  67.                 case 0:
  68.                 case 5:
  69.                     root.setX(root.x + delta.x)
  70.                     root.setY(root.y + delta.y)
  71.                     break;
  72.                 case 1:
  73.                     // TODO: 缩放功能目前有bug,先不上线
  74.                     //                    root.width = root.width - delta.x;
  75.                     //                    root.height = root.height - delta.y
  76.                     root.setX(root.x + delta.x)
  77.                     root.setY(root.y + delta.y)
  78.                     break;
  79.                 case 2:
  80.                     //                    root.width = root.width - delta.x;
  81.                     root.setX(root.x + delta.x)
  82.                     break;
  83.                 case 3:
  84.                     //                    root.width = root.width - delta.x;
  85.                     //                    root.height = root.height + delta.y;
  86.                     root.setX(root.x + delta.x)
  87.                     clickPos = Qt.point(mouse.x, mouse.y)
  88.                     break;
  89.                 case 4:
  90.                     //                    root.height = root.height - delta.y
  91.                     root.setY(root.y + delta.y)
  92.                     break;
  93.                 case 6:
  94.                     //                    root.height = root.height + delta.y;
  95.                     clickPos = Qt.point(mouse.x, mouse.y)
  96.                     break;
  97.                 case 7:
  98.                     //                    root.width = root.width + delta.x;
  99.                     //                    root.height = root.height - delta.y;
  100.                     root.setY(root.y + delta.y)
  101.                     clickPos = Qt.point(mouse.x, mouse.y)
  102.                     break;
  103.                 case 8:
  104.                     //                    root.width = root.width + delta.x;
  105.                     clickPos = Qt.point(mouse.x, mouse.y)
  106.                     break;
  107.                 case 9:
  108.                     //                    root.width = root.width + delta.x;
  109.                     //                    root.height = root.height + delta.y;
  110.                     clickPos = Qt.point(mouse.x, mouse.y)
  111.                     break;
  112.                 default:
  113.                     break;
  114.                 }
  115.                 // 防止页面消失
  116.                 if(root.width < minWidthHeight){
  117.                     root.width = minWidthHeight;
  118.                 }
  119.                 if(root.height < minWidthHeight){
  120.                     root.height = minWidthHeight;
  121.                 }

  122.             }
  123.             /* TODO: 鼠标改变窗口大小的功能实现有bug, 在右下角经常无法触发鼠标,因此屏蔽这个功能
  124.                 else
  125.                 {
  126.                     // 没有按左键,只需要改变鼠标形状
  127.                     if(mou** <= step && mou** > 0){
  128.                         // 九宫格左侧三个格子,宽度 step, 分别处理三个格子区域的鼠标形状
  129.                         if(mouseY < step && mouseY > 0){
  130.                             // 第一行
  131.                             mouseState = 1;
  132.                             rootMouseArea.cursorShape = Qt.SizeFDiagCursor;
  133.                         }
  134.                         else if(mouseY >= step && mouseY < root.height - step){
  135.                             // 第二行
  136.                             mouseState = 2;
  137.                             rootMouseArea.cursorShape = Qt.SizeHorCursor;
  138.                         }
  139.                         else if(mouseY >= root.height - step && mouseY <= root.height){
  140.                             // 第三行
  141.                             mouseState = 3;
  142.                             rootMouseArea.cursorShape = Qt.SizeBDiagCursor;
  143.                         }
  144.                     }
  145.                     else if(mou** > step && mou** <= root.width - step){
  146.                         // 九宫格中间第二列的三行
  147.                         if(mouseY < step && mouseY > 0){
  148.                             mouseState = 4;
  149.                             rootMouseArea.cursorShape = Qt.SizeVerCursor;
  150.                         }
  151.                         else if(mouseY >= step && mouseY < root.height - step){
  152.                             mouseState = 5;
  153.                             rootMouseArea.cursorShape = Qt.ArrowCursor;
  154.                         }
  155.                         else if(mouseY >= root.height - step && mouseY <= root.height){
  156.                             mouseState = 6;
  157.                             rootMouseArea.cursorShape = Qt.SizeVerCursor;
  158.                         }
  159.                     }
  160.                     else if(mou** > root.width - step && mou** <= root.width){
  161.                         // 九宫格中间第三列的三行
  162.                         if(mouseY <= step && mouseY > 0){
  163.                             mouseState = 7;
  164.                             rootMouseArea.cursorShape = Qt.SizeBDiagCursor;
  165.                         }
  166.                         else if(mouseY > step && mouseY < root.height - step){
  167.                             mouseState = 8;
  168.                             rootMouseArea.cursorShape = Qt.SizeHorCursor;
  169.                         }
  170.                         else if((mouseY >= (root.height - step)) && mouseY <= root.height){
  171.                             mouseState = 9;
  172.                             rootMouseArea.cursorShape = Qt.SizeFDiagCursor;
  173.                         }
  174.                     }
  175.                 }
  176.             */
  177.             mouse.accepted = true;
  178.         }
  179.     }

  180.     GridLayout {
  181.         id: rootGL;
  182.         anchors.fill: parent;
  183.         rows: 2; columns: 2;
  184.         rowSpacing: 0; columnSpacing: 0;

  185.         // 标题名称背景图, LOGO,最小化,最大化,关闭按钮
  186.         Rectangle {
  187.             id: titleBar;
  188.             Layout.rowSpan: 1; Layout.columnSpan: 2;
  189.             Layout.fillHeight: true; Layout.fillWidth: true;
  190.             Layout.minimumWidth: 960; Layout.maximumWidth: 1920;
  191.             Layout.minimumHeight: 75; Layout.maximumHeight: 145;
  192.             Layout.preferredWidth: 960; Layout.preferredHeight: 75;
  193.             Layout.topMargin: 20;
  194.             Layout.leftMargin: 15;
  195.             Layout.rightMargin: 15;
  196.             color: "transparent";

  197.             // 背景图
  198.             Image {
  199.                 id: titleImg;
  200.                 // 30 是量 root._width,root._height 的图片中背景图的
  201.                 // 左边加右边的距离,得出宽度,同理得出相对高度,以下都是
  202.                 // 类似计算方法;
  203.                 width: root.width - 30 * root.hRatio;
  204.                 height: 55 * root.vRatio;
  205.                 source: "qrc:/image/title.png";
  206.                 fillMode: Image.Stretch;
  207.                 anchors.left: parent.left;
  208.                 anchors.top: parent.top;
  209.                 z: 0;
  210.             }
  211.             // LOGO
  212.             Image {
  213.                 id: logo;
  214.                 width: root.width * (568 / 1920);
  215.                 height: logo.width * (48 / 568);
  216.                 source: "qrc:/image/logo.png";
  217.                 fillMode: Image.Stretch;
  218.                 anchors.left: titleImg.left
  219.                 anchors.leftMargin: 27 * root.hRatio;
  220.                 anchors.top: titleImg.top;
  221.                 anchors.topMargin: 32 * ( root.height / root._height);
  222.                 z: 1;
  223.             }

  224.             Rectangle {
  225.                 id: titlebar;
  226.                 width: 76;
  227.                 height: 20;
  228.                 anchors.right: titleImg.right;
  229.                 anchors.top: titleImg.top;
  230.                 anchors.topMargin: 20 * root.vRatio;
  231.                 color: "transparent";
  232.                 property bool isMax: false;

  233.                 // 最小化, 最大化, 关闭按钮
  234.                 Button {
  235.                     id: closeButton;
  236.                     width: 22 * root.hRatio; height:22 * root.vRatio;
  237.                     anchors.right: parent.right;
  238.                     anchors.rightMargin: 23 * root.hRatio;
  239.                     anchors.top: parent.top;
  240.                     ToolTip.text: "关闭";
  241.                     ToolTip.visible: hovered;

  242.                     onClicked: {
  243.                         // TODO: 增加相应的退出处理
  244.                         Qt.quit();
  245.                     }

  246.                     background: Rectangle {
  247.                         color: (closeButton.hovered | closeButton.pressed) ? "red" : "transparent";
  248.                         radius: width / 2;
  249.                         BorderImage {
  250.                             anchors.fill: parent;
  251.                             source: "qrc:/image/close.png";
  252.                         }
  253.                     }
  254.                 }
  255.                 Button {
  256.                     id: maxButton;
  257.                     width: 22 * root.hRatio; height: 22 * root.vRatio;
  258.                     anchors.right: closeButton.left;
  259.                     anchors.rightMargin: 8 * root.hRatio;
  260.                     anchors.top: closeButton.top;
  261.                     ToolTip.text: parent.isMax ? "还原" : "最大化";
  262.                     ToolTip.visible: hovered;
  263.                     Image {
  264.                         id: btnImage;
  265.                         fillMode: Image.Stretch;
  266.                         width: parent.width; height: parent.height;
  267.                         source: "qrc:/image/max.png";
  268.                     }
  269.                     background: Rectangle{
  270.                         color: "transparent";
  271.                     }

  272.                     onClicked: {
  273.                         handleMaxButton();
  274.                     }
  275.                 }
  276.                 Button {
  277.                     id: minButton;
  278.                     width: 22 * root.hRatio; height: 22 * root.vRatio;
  279.                     anchors.right: maxButton.left;
  280.                     anchors.rightMargin: 8 * root.hRatio;
  281.                     anchors.top: closeButton.top;
  282.                     ToolTip.text: "最小化";
  283.                     ToolTip.visible: hovered;
  284.                     background: Rectangle {
  285.                         color: "transparent";
  286.                         BorderImage {
  287.                             anchors.fill: parent;
  288.                             source: "qrc:/image/min.png";
  289.                         }
  290.                     }
  291.                     onClicked: root.visibility =  Window.Minimized;
  292.                 }
  293.             }
  294.         }

  295.         Rectangle {
  296.             Layout.rowSpan: 1; Layout.columnSpan: 2;
  297.             Layout.fillHeight: true; Layout.fillWidth: true;
  298.             Layout.minimumWidth: 960; Layout.maximumWidth: 1920;
  299.             Layout.minimumHeight: 465; Layout.maximumHeight: 935;
  300.             Layout.preferredWidth: 960; Layout.preferredHeight: 465;
  301.             color: "transparent";
  302.             // 按钮导航栏
  303.             Rectangle {
  304.                 id: leftNav;
  305.                 width: 300 * root.hRatio;
  306.                 height: 360 * root.vRatio;
  307.                 color: "transparent";

  308.                 Button {
  309.                     id: displaybtn;
  310.                     // 原图是 1920 * 1080 的图,Button 是 383 * 80的大小
  311.                     width: 383 * (root.width / 1920);
  312.                     height: 80 * (root.height / 1080);
  313.                     anchors.right: parent.right;
  314.                     anchors.rightMargin: 58 * root.hRatio;
  315.                     anchors.top: parent.top;
  316.                     anchors.topMargin: 30 * root.vRatio;
  317.                     background: Rectangle {
  318.                         color: (displaybtn.hovered | displaybtn.pressed) ? "#42A1FA" : "transparent";
  319.                         radius: width / 2;
  320.                         BorderImage {
  321.                             anchors.fill: parent;
  322.                             source: "qrc:/image/display.png";
  323.                         }
  324.                     }
  325.                     onClicked: {
  326.                         mainView.currentIndex = 0;
  327.                     }
  328.                 }
  329.                 Button {
  330.                     id: combtn;
  331.                     // 原图是 1920 * 1080 的图,Button 是 383 * 80的大小
  332.                     width: 383 * (root.width / 1920);
  333.                     height: 80 * (root.height / 1080);
  334.                     anchors.right: parent.right;
  335.                     anchors.rightMargin: 58 * root.hRatio;
  336.                     anchors.top: displaybtn.bottom;
  337.                     anchors.topMargin: 40 * root.vRatio;
  338.                     background: Rectangle {
  339.                         color: (combtn.hovered | combtn.pressed) ? "#42A1FA" : "transparent";
  340.                         radius: width / 2;
  341.                         BorderImage {
  342.                             anchors.fill: parent;
  343.                             source: "qrc:/image/com.png";
  344.                         }
  345.                     }
  346.                     onClicked: {
  347.                         mainView.currentIndex = 1;
  348.                     }
  349.                 }
  350.                 Button {
  351.                     id: modbusbtn;
  352.                     // 原图是 1920 * 1080 的图,Button 是 383 * 80的大小
  353.                     width: 383 * (root.width / 1920);
  354.                     height: 80 * (root.height / 1080);
  355.                     anchors.right: parent.right;
  356.                     anchors.rightMargin: 58 * root.hRatio;
  357.                     anchors.top: combtn.bottom;
  358.                     anchors.topMargin: 40 * root.vRatio;
  359.                     background: Rectangle {
  360.                         color: (modbusbtn.hovered | modbusbtn.pressed) ? "#42A1FA" : "transparent";
  361.                         radius: width / 2;
  362.                         BorderImage {
  363.                             anchors.fill: parent;
  364.                             source: "qrc:/image/modbus.png";
  365.                         }
  366.                     }
  367.                     onClicked: {
  368.                         mainView.currentIndex = 2;
  369.                     }
  370.                 }
  371.                 Button {
  372.                     id: readbtn;
  373.                     // 原图是 1920 * 1080 的图,Button 是 383 * 80的大小
  374.                     width: 383 * (root.width / 1920);
  375.                     height: 80 * (root.height / 1080);
  376.                     anchors.right: parent.right;
  377.                     anchors.rightMargin: 58 * root.hRatio;
  378.                     anchors.top: modbusbtn.bottom;
  379.                     anchors.topMargin: 40 * root.vRatio;
  380.                     background: Rectangle {
  381.                         color: (readbtn.hovered | readbtn.pressed) ? "#42A1FA" : "transparent";
  382.                         radius: width / 2;
  383.                         BorderImage {
  384.                             anchors.fill: parent;
  385.                             source: "qrc:/image/read.png";
  386.                         }
  387.                     }
  388.                     onClicked: {
  389.                         mainView.currentIndex = 3;
  390.                     }
  391.                 }
  392.                 Button {
  393.                     id: writebtn;
  394.                     // 原图是 1920 * 1080 的图,Button 是 383 * 80的大小
  395.                     width: 383 * (root.width / 1920);
  396.                     height: 80 * (root.height / 1080);
  397.                     anchors.right: parent.right;
  398.                     anchors.rightMargin: 58 * root.hRatio;
  399.                     anchors.top: readbtn.bottom;
  400.                     anchors.topMargin: 40 * root.vRatio;
  401.                     background: Rectangle {
  402.                         color: (writebtn.hovered | writebtn.pressed) ? "#42A1FA" : "transparent";
  403.                         radius: width / 2;
  404.                         BorderImage {
  405.                             anchors.fill: parent;
  406.                             source: "qrc:/image/write.png";
  407.                         }
  408.                     }
  409.                     onClicked: {
  410.                         mainView.currentIndex = 4;
  411.                     }
  412.                 }
  413.             }

  414.             StackLayout {
  415.                 id: mainView;
  416.                 width: 600 * root.hRatio;
  417.                 height: 420 * root.vRatio;
  418.                 anchors.left: leftNav.right;

  419.                 Loader {
  420.                     id: home;
  421.                     source: "qrc:/Home.qml"
  422.                 }
  423.                 Loader {
  424.                     id: comConfig;
  425.                     source: "./ComConfig.qml";
  426.                 }
  427.                 Loader {
  428.                     id: modbusTest;
  429.                     source: "qrc:/ModbusTest.qml";
  430.                 }
  431.                 Loader {
  432.                     id: readCmd;
  433.                     source: "qrc:/ReadCmd.qml";
  434.                 }
  435.                 Loader {
  436.                     id: modifyCmd;
  437.                     source: "qrc:/ModifyCmd.qml";
  438.                 }
  439.             }
  440.         }
  441.     }


  442.     // 主页的 js 全局函数
  443.     function handleMaxButton(){
  444.         if(titlebar.isMax){
  445.             root.visibility =  Window.Windowed;
  446.             titlebar.isMax = false;
  447.             btnImage.source = "qrc:/image/max.png";
  448.         }else{
  449.             root.visibility =  Window.Maximized;
  450.             titlebar.isMax = true;
  451.             btnImage.source = "qrc:/image/reset.png";
  452.         }
  453.     }

  454.     Component.onCompleted: {
  455.         mainView.currentIndex = 0
  456.     }


  457.     // C++ 扩展类, 用于处理 modbus 通信;
  458.     // 所有的页面最终都通过这个对象进行通信
  459.     HandleHumiture {
  460.         id: handle;
  461.     }
  462.     // comConfig 的通信
  463.     Connections {
  464.         target: comConfig.item;
  465.         onOpenModbus: {
  466.             console.log("comNo: ", device, "baud: ", baud);
  467.             handle.onOpenCom(device, baud);
  468.         }
  469.     }
  470.     Connections {
  471.         target: comConfig.item;
  472.         onClose: {
  473.             handle.onCloseCom();
  474.         }
  475.     }
  476.     Connections {
  477.         target: handle; // handle 发过来结果, 同样的 下面的参数  result, baud等也是未定义
  478.         onComOpenResult: {
  479.             comConfig.item.openFb(result, baud, stopbits, parity, databits);
  480.         }
  481.     }
  482.     Connections {
  483.         target: handle; // handle 发过来结果
  484.         onComCloseResult: {
  485.             comConfig.item.closeFb();
  486.         }
  487.     }
  488. }
复制代码
回复

使用道具 举报

累计签到:12 天
连续签到:1 天
2019-5-17 17:50:46 显示全部楼层
测试后C++扩展的信号同样是无法得到 参数
回复

使用道具 举报

累计签到:12 天
连续签到:1 天
2019-5-17 17:52:46 显示全部楼层
@yafeilinux 首次在正式项目用了 qml 的方式构建界面,麻烦看下这个问题;现在导致项目延期了
下面是 main.cpp 代码:
  1. #include <QQmlApplicationEngine>
  2. #include <QtWidgets/QApplication>
  3. #include <QtQuick/QQuickView>
  4. #include <QtCore/QDir>
  5. #include <QtQml/QQmlEngine>
  6. #include "handlehumiture.h"


  7. int main(int argc, char *argv[])
  8. {
  9.     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  10.     QApplication app(argc, argv);

  11.     qmlRegisterType<HandleHumiture>("an.qt.HandleHumiture", 1, 0, "HandleHumiture");

  12.     QQmlApplicationEngine engine;
  13.     const QUrl url(QStringLiteral("qrc:/main.qml"));
  14.     QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
  15.                      &app, [url](QObject *obj, const QUrl &objUrl) {
  16.         if (!obj && url == objUrl)
  17.             QCoreApplication::exit(-1);
  18.     }, Qt::QueuedConnection);
  19.     engine.load(url);

  20.     return app.exec();
  21. }
复制代码

点评

不用贴这么多代码,直接说自己的问题就行。建议新建一个空项目,单独测试出现的问题。  详情 回复 发表于 2019-5-17 18:09
回复

使用道具 举报

累计签到:1568 天
连续签到:1 天
2019-5-17 18:09:47 显示全部楼层
北辰 发表于 2019-5-17 17:52
@yafeilinux 首次在正式项目用了 qml 的方式构建界面,麻烦看下这个问题;现在导致项目延期了
下面是 main. ...

不用贴这么多代码,直接说自己的问题就行。建议新建一个空项目,单独测试出现的问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了