当前位置: 首页 > news >正文

手表网站建站室内设计公司排名及案例

手表网站建站,室内设计公司排名及案例,江西数据平台网站建设,wordpress主题换图片不显示文章目录 一、C文件Demo二、使用步骤1. 初始化C文件和QML文件#xff0c;并建立信号槽2.在qml中调用 一、C文件Demo Q_INVOKABLE是一个Qt元对象系统中的宏#xff0c;用于将C函数暴露给QML引擎。具体来说#xff0c;它使得在QML代码中可以直接调用C类中被标记为Q_INVOKABLE的… 文章目录 一、C文件Demo二、使用步骤1. 初始化C文件和QML文件并建立信号槽2.在qml中调用 一、C文件Demo Q_INVOKABLE是一个Qt元对象系统中的宏用于将C函数暴露给QML引擎。具体来说它使得在QML代码中可以直接调用C类中被标记为Q_INVOKABLE的成员函数。 public:SerialPort();// 返回可用串口Q_INVOKABLE QStringList availablePorts();// 打开串口Q_INVOKABLE bool open(QString portName, QString buadRate, QString dataBits, QString stopBits,QString parity, QString flowControl);// 关闭串口Q_INVOKABLE void close();// 直接调用接口Q_INVOKABLE void say();signals://返回串口打开信息Q_INVOKABLE void openMsg(bool open, QString error);//接口用于多线程Q_INVOKABLE void sendMsg(QString msg);public slots://void sendMsgSlot(QString msg);private:QThread* m_thread;QSerialPort* m_port;QMutex m_mutex;m_port new QSerialPort(); connect(this, SerialPort::sendMsg, this, SerialPort::sendMsgSlot);tts new QTextToSpeech(this);m_thread new QThread; m_thread-setObjectName(串口线程); this-moveToThread(m_thread); connect(m_thread, QThread::finished, this, QThread::deleteLater); connect(m_thread, QThread::finished, this, SerialPort::deleteLater); m_thread-start();QStringList SerialPort::availablePorts() {QStringList list;foreach(auto info, QSerialPortInfo::availablePorts()) list.append(info.portName());listCOM11COM22;return list; }bool SerialPort::open(QString portName, QString buadRate, QString dataBits, QString stopBits,QString parity, QString flowControl) {bool ok false;QString errstr m_port异常;{QMutexLocker locker(m_mutex);if(!m_port){emit openMsg(false, errstr);locker.unlock();return false;}m_port-setPortName(portName);m_port-setBaudRate(buadRate.toInt());m_port-setDataBits((QSerialPort::DataBits)dataBits.toInt());m_port-setStopBits((QSerialPort::StopBits)stopBits.toInt());m_port-setParity((QSerialPort::Parity)parity.toInt());m_port-setFlowControl((QSerialPort::FlowControl)flowControl.toInt());ok m_port-open(QIODevice::ReadWrite);errstr m_port-errorString();}emit openMsg(ok, errstr);return ok; }void SerialPort::close() {QMutexLocker locker(m_mutex);if(m_port m_port-isOpen()) m_port-close(); }void SerialPort::say() {qDebug()SerialPort CurrrntThread QThread::currentThread();qDebug()---------------------------------------------------------;QString text 2,8,k,1,0;tts-say(text); }void SerialPort::sendMsgSlot(QString msg) {qDebug()SerialPort CurrrntThread QThread::currentThread();qDebug()msg;qDebug()---------------------------------------------------------; }二、使用步骤 1. 初始化C文件和QML文件并建立信号槽 qml中的槽函数也是定义成signal, 所以connect时槽函数也是SIGNAL() serial new SerialPort; //serial 类向 QML 对象的上下文公开数据 ui-quickWidget_2-rootContext()-setContextProperty(serial, serial); //根据窗口大小调整QML大小 ui-quickWidget_2-setResizeMode(QQuickWidget::SizeRootObjectToView); // ui-quickWidget_2-setSource(QUrl(qrc:/Form02.qml)); // QObject* obj ui-quickWidget_2-rootObject(); // 调用qml中信号或者槽函数调用成功返回true否则false // 根节点被调用信号或槽连接方式被调用信号或槽的参数1 被调用信号或槽的参数2(最多10个参数) if(QMetaObject::invokeMethod(obj, slotOpenSerial, Qt::DirectConnection, Q_ARG(bool, true), Q_ARG(QString, )))connect(serial, SIGNAL(openMsg(bool,QString)), obj, SIGNAL(slotOpenSerial(bool,QString)));2.在qml中调用 QGroupButton 自定义的按钮组 Item {id: itemLayout.fillWidth: trueLayout.preferredHeight: 36property alias checkedButton: btngroup.checkedButtonproperty int btnIndexChanged: 0onBtnIndexChangedChanged: {if(btnIndexChanged 0) {checkedButton ok}else {checkedButton cancle}}ButtonGroup {id: btngroupexclusive: truebuttons: row.childrenonCheckedButtonChanged:{console.log(button text: , checkedButton.text)btnIndexChanged checkedButton ok ? 0 : 1;}}Rectangle{id: rectanchors.fill: parentRowLayout {id: rowanchors.fill: rectspacing: 6QButton{id: ok; text: OK}QButton{id: cancle; text: Cancle}}} }signal slotOpenSerial(bool isOpen, string error)onSlotOpenSerial: {//console.log(isOpen, error)if(!isOpen){group.btnIndexChanged 1} }qrc:/Form02.qml //自定义的按钮组 QGroupButton{id: groupLayout.columnSpan: 2Layout.fillWidth: trueonCheckedButtonChanged:{if(checkedButton.text OK){open serial.open(portName.currentText, cboxBuad.currentText, dataBits.currentText,stopBits.currentText, parity.currentText, flowControl.currentText);console.log(serial return: , open)}else{serial.close()}} }下面代码仅看这段 QButton{ text: 1; onClicked: { //直接调用接口 serial.say(); //通过信号调用 serial.sendMsg(TTTT); } } Rectangle {Layout.columnSpan: 2Layout.fillWidth: trueLayout.fillHeight: truecolor: #156448Flow {anchors.fill: parentanchors.margins: 9spacing: 6QButton{text: 1;onClicked: {serial.say();serial.sendMsg(TTTT);}}QButton{text: 2}QButton{text: 3}QButton{text: 4}QButton{text: 5}QButton{text: 6}QButton{text: 7}QButton{text: 8}QButton{text: 9}QButton{text: 10}QButton{text: 11}QButton{text: 12}QButton{text: 13}QButton{text: 14}QButton{text: 15}QButton{text: 16}QButton{text: 17}QButton{text: 18}QButton{text: 19}Rectangle {width:60height: 26color: greenproperty alias text: in1.textonTextChanged: console.log(text)TextInput {id: in1anchors.fill: parenttext: inputcolor: redKeyNavigation.tab: in2selectByMouse: true}}Rectangle {width:60height: 26color: greenTextInput {id: in2anchors.fill: parenttext: inputcolor: redKeyNavigation.tab: in1KeyNavigation.up: in1}}Loader {sourceComponent: testComponent}} }结果如图 //--------------------------------------------------------- MainWindow CurrentThread QThread(0x24ce850) //主线程 //--------------------------------------------------------- qml: button text: OK // 点击OK按钮打印 qml: button text: Cancle // 打开串口失败取消OK按钮默认Cancle按钮被点击打印 qml: serial return: false // serial.open(…)返回值打印 SerialPort CurrrntThread QThread(0x24ce850) // serial.say() 函数运行的线程 //--------------------------------------------------------- SerialPort CurrrntThread QThread(0xfcc9f0, name “串口线程”) // serial.sendMsg(“TTTT”)运行的线程 “TTTT” // 槽函数打印 //---------------------------------------------------------
http://www.hkea.cn/news/14425788/

相关文章:

  • WordPress增加下载按钮扬州seo推广
  • 建设部网站核对编号网络平台运营是做什么的
  • 鞍山网站建设联系方式哪些网站可以做任务挣钱
  • 成都营销类网站设计查询网站后台地址
  • 哪有备案好的网站网站开发代码说明书
  • 合肥网站制作开发金华网站建设微信开发
  • 主办单位性质与网站名称不符有什么做h5的网站
  • 哪个网站做图找图片怎样用代码建设一个网站
  • 泰州网站优化公司吴中网站开发建设多少钱
  • 郑州做网站公司msgg手机怎么做图纸设计
  • jsp网站开发详解 pdf免费psd图片素材网站
  • 如何做律师网站泰安人才市场最新招聘信息
  • 阿里云服务器 网站模板千锋教育介绍
  • 网站制作 呼和浩特唐山做网站公司汉狮价格
  • 济南品牌网站建设价格低佛山市城乡住房建设局网站首页
  • 织梦小说网站源wap站建设部物业证书查询官方网站
  • 国内网站开发wordpress幻灯片图片主题
  • 中文博客网站模板下载邢台有限公司
  • 贵州省教育厅办公室关于开展2014年学校门户网站建设评估的通知网站建设及验收标准
  • 开发的网站公司网站在哪备案
  • 虚拟主机如何分配网站北京昌平区
  • 南京网站制作公司莱芜最好的网站建设公司
  • 网站建设都包括吉利网站建设
  • 公司网站制作网络公司跳转到另一个网站怎么做
  • 怎么样可以自己做网站软件开发与应用
  • 1688做网站需要多少钱服务行业做网站
  • 做视频网站赚钱网页分析工具
  • 购物网站框架2015做啥网站致富
  • 泉州鲤城网站建设html编程题题库
  • 怎么做网址导航网站企业信用信息公示系统查询