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

江苏省建设斤网站推广app赚佣金平台有哪些

江苏省建设斤网站,推广app赚佣金平台有哪些,手机网站建设的公司,网站开发开题报告ppt目录 1 QML获取C的变量值 2 QML获取C创建的自定义对象 3 QML发送信号绑定C端的槽 4 C端发送信号绑定qml端槽 5 C调用QML端函数 1 QML获取C的变量值 QQmlApplicationEngine engine; 全局对象 上下文属性 QQmlApplicationEngine engine; QQmlContext *context1 engine.…

目录

1 QML获取C++的变量值

2 QML获取C++创建的自定义对象

3 QML发送信号绑定C++端的槽

4 C++端发送信号绑定qml端槽

5 C++调用QML端函数


1 QML获取C++的变量值
QQmlApplicationEngine engine;

全局对象

上下文属性

QQmlApplicationEngine engine;
QQmlContext *context1 = engine.rootContext();
context1->setContextProperty("test",200);

在qml中可全局直接使用test 

2 QML获取C++创建的自定义对象

光标放在成员变量m_iValue和m_sString后面 Alt + Enter 选择第一个可自动生成函数

int m_iValue;
QString m_sString;

myobject.h

#ifndef MYOBJECT_H
#define MYOBJECT_H#include <QObject>class MyObject : public QObject
{Q_OBJECT
public:explicit MyObject(QObject *parent = nullptr);int iValue() const;void setIValue(int newIValue);const QString &sString() const;void setSString(const QString &newSString);signals:void iValueChanged();void sStringChanged();private:int m_iValue;QString m_sString;Q_PROPERTY(int iValue READ iValue WRITE setIValue NOTIFY iValueChanged)Q_PROPERTY(QString sString READ sString WRITE setSString NOTIFY sStringChanged)
};#endif // MYOBJECT_H

myobject.c

#include "myobject.h"MyObject::MyObject(QObject *parent): QObject{parent}
{}int MyObject::iValue() const
{return m_iValue;
}void MyObject::setIValue(int newIValue)
{if (m_iValue == newIValue)return;m_iValue = newIValue;emit iValueChanged();
}const QString &MyObject::sString() const
{return m_sString;
}void MyObject::setSString(const QString &newSString)
{if (m_sString == newSString)return;m_sString = newSString;emit sStringChanged();
}

mian.c

注册main.qml 中 import testObj 1.0使用

qmlRegisterType<MyObject>("testObj",1,0,"MyObject");

main.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.5
import testObj 1.0
Window {width: 640height: 480visible: truetitle: qsTr("Hello World")MyObject {iValue: 20sString: "test"}}

使用c++端的函数时需要在函数前面加上 Q_INVOKABLE

比如 Q_INVOKABLE void myFunction();

3 QML发送信号绑定C++端的槽

在mian.c先注册 qmlRegisterType<MyObject>("testObj",1,0,"MyObject");

C++ 写一个公有槽 

public slots:
    void qml_slot(QString str);

qml端通过按钮发送信号

signal qml_signal(string str)
    Button {
        onClicked: {
            qml_signal("qml send signal test");
        }
    }

绑定信号和槽函数

Component.onCompleted: {
        qml_signal.connect(myobj.qml_slot)
    }

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.5
import testObj 1.0
Window {id: windowwidth: 640height: 480visible: truetitle: qsTr("Hello World")MyObject {id: myobjiValue: 20sString: "test"}signal qml_signal(string str)Button {onClicked: {qml_signal("qml send signal test");}}//方法一
//    Connections {
//        target: window
//        function onQml_signal(str){
//            myobj.qml_slot(str)
//        }
//    }//方法二Component.onCompleted: {qml_signal.connect(myobj.qml_slot)}//方法三 mian.c 中engine load后//auto obj_list = engine.rootObjects();//auto window = list.first();//connect(window,SIGNAL(qml_signal(QString)),your function ptr,SLOT(qml_slot(QString)));}
4 C++端发送信号绑定qml端槽

myobject.h

信号 void signal_Cpp(QString str); 通过函数

Q_INVOKABLE void myFunction();发送
#ifndef MYOBJECT_H
#define MYOBJECT_H#include <QObject>class MyObject : public QObject
{Q_OBJECT
public:explicit MyObject(QObject *parent = nullptr);int iValue() const;void setIValue(int newIValue);const QString &sString() const;void setSString(const QString &newSString);Q_INVOKABLE void myFunction();static MyObject* getInstance();
public slots:void qml_slot(QString str);
signals:void iValueChanged();void sStringChanged();void signal_Cpp(QString str);
private:int m_iValue;QString m_sString;Q_PROPERTY(int iValue READ iValue WRITE setIValue NOTIFY iValueChanged)Q_PROPERTY(QString sString READ sString WRITE setSString NOTIFY sStringChanged)
};#endif // MYOBJECT_H

myobject.c

#include "myobject.h"
#include <QDebug>
MyObject::MyObject(QObject *parent): QObject{parent}
{}int MyObject::iValue() const
{return m_iValue;
}void MyObject::setIValue(int newIValue)
{if (m_iValue == newIValue)return;m_iValue = newIValue;emit iValueChanged();
}const QString &MyObject::sString() const
{return m_sString;
}void MyObject::setSString(const QString &newSString)
{if (m_sString == newSString)return;m_sString = newSString;emit sStringChanged();
}void MyObject::myFunction()
{emit signal_Cpp("signal_Cpp myFunction!");
}MyObject *MyObject::getInstance()
{static MyObject* obj = new MyObject();return obj;
}void MyObject::qml_slot(QString str)
{qDebug()<<"qml_slot"<<str;
}

mian.c

注册单例类

qmlRegisterSingletonInstance("testObj",1,0,"MyObject",MyObject::getInstance());
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QtQml/qqml.h>
#include "myobject.h"int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endifQGuiApplication app(argc, argv);QQmlApplicationEngine engine;QQmlContext *context1 = engine.rootContext();context1->setContextProperty("test",200);//qmlRegisterType<MyObject>("testObj",1,0,"MyObject");qmlRegisterSingletonInstance("testObj",1,0,"MyObject",MyObject::getInstance());const QUrl url(QStringLiteral("qrc:/main.qml"));QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,&app, [url](QObject *obj, const QUrl &objUrl) {if (!obj && url == objUrl)QCoreApplication::exit(-1);}, Qt::QueuedConnection);engine.load(url);return app.exec();
}

main.qml

C++端发送信号

Button {
        onClicked: {
            //C++发送信号
            MyObject.myFunction()
        }
    }

连接QML端槽函数

Connections {
        target: MyObject
        function onSignal_Cpp(str) {
            //qml槽函数
            qmlSolt(str)
        }
    }

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.5
import testObj 1.0
Window {id: windowwidth: 640height: 480visible: truetitle: qsTr("Hello World")//    MyObject {
//        id: myobj
//        iValue: 20
//        sString: "test"//    }function qmlSolt(str) {console.log(str)}signal qml_signal(string str)Button {onClicked: {//C++发送信号MyObject.myFunction()}}Connections {target: MyObjectfunction onSignal_Cpp(str) {//qml槽函数qmlSolt(str)}}}
5 C++调用QML端函数

//main.c  load后获取qml对象
    auto obj_list = engine.rootObjects();
    auto window = obj_list.first();

 //调用QML函数
    QMetaObject::invokeMethod(window,"qmlFunction",
                              Q_RETURN_ARG(QVariant,res),
                              Q_ARG(QVariant,arg1),
                              Q_ARG(QVariant,arg2)
                              );

mian.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.5
import testObj 1.0
Window {id: windowwidth: 640height: 480visible: truetitle: qsTr("Hello World")function qmlFunction(arg1,arg2) {return arg1 + arg2;}}

mian.c

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QtQml/qqml.h>
#include "myobject.h"int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endifQGuiApplication app(argc, argv);QQmlApplicationEngine engine;QQmlContext *context1 = engine.rootContext();context1->setContextProperty("test",200);qmlRegisterType<MyObject>("testObj",1,0,"MyObject");//qmlRegisterSingletonInstance("testObj",1,0,"MyObject",MyObject::getInstance());const QUrl url(QStringLiteral("qrc:/main.qml"));QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,&app, [url](QObject *obj, const QUrl &objUrl) {if (!obj && url == objUrl)QCoreApplication::exit(-1);}, Qt::QueuedConnection);engine.load(url);//获取qml对象auto obj_list = engine.rootObjects();auto window = obj_list.first();QVariant res;QVariant arg1 = "arg1";QVariant arg2 = "arg2";//调用QML函数QMetaObject::invokeMethod(window,"qmlFunction",Q_RETURN_ARG(QVariant,res),Q_ARG(QVariant,arg1),Q_ARG(QVariant,arg2));qDebug()<<res;return app.exec();
}


文章转载自:
http://misled.xzLp.cn
http://photolitho.xzLp.cn
http://dibasic.xzLp.cn
http://chronopher.xzLp.cn
http://infraction.xzLp.cn
http://sial.xzLp.cn
http://lav.xzLp.cn
http://leguleian.xzLp.cn
http://decouple.xzLp.cn
http://sass.xzLp.cn
http://type.xzLp.cn
http://illuminaten.xzLp.cn
http://elsa.xzLp.cn
http://miracle.xzLp.cn
http://squitch.xzLp.cn
http://refold.xzLp.cn
http://psoralen.xzLp.cn
http://undying.xzLp.cn
http://aeruginous.xzLp.cn
http://reptant.xzLp.cn
http://laffer.xzLp.cn
http://damagingly.xzLp.cn
http://harem.xzLp.cn
http://fangle.xzLp.cn
http://taleteller.xzLp.cn
http://selectorate.xzLp.cn
http://jervis.xzLp.cn
http://calcicole.xzLp.cn
http://uneasily.xzLp.cn
http://symbolic.xzLp.cn
http://hemicrania.xzLp.cn
http://interferometric.xzLp.cn
http://ingravescence.xzLp.cn
http://pokie.xzLp.cn
http://chabasite.xzLp.cn
http://magnanimity.xzLp.cn
http://retirement.xzLp.cn
http://hierarchize.xzLp.cn
http://conglomeration.xzLp.cn
http://pulmometry.xzLp.cn
http://sesterce.xzLp.cn
http://spirometry.xzLp.cn
http://supplier.xzLp.cn
http://sanguinariness.xzLp.cn
http://brock.xzLp.cn
http://phylesis.xzLp.cn
http://gertcha.xzLp.cn
http://sarcous.xzLp.cn
http://ingot.xzLp.cn
http://ionisation.xzLp.cn
http://mediative.xzLp.cn
http://poplin.xzLp.cn
http://idli.xzLp.cn
http://merriness.xzLp.cn
http://peristalsis.xzLp.cn
http://whatnot.xzLp.cn
http://suboesophageal.xzLp.cn
http://fisher.xzLp.cn
http://omnificent.xzLp.cn
http://unfrock.xzLp.cn
http://sculp.xzLp.cn
http://chebec.xzLp.cn
http://dibasic.xzLp.cn
http://outvie.xzLp.cn
http://someway.xzLp.cn
http://moderate.xzLp.cn
http://artifice.xzLp.cn
http://liederkranz.xzLp.cn
http://any.xzLp.cn
http://inductivism.xzLp.cn
http://theatromania.xzLp.cn
http://xantippe.xzLp.cn
http://separatum.xzLp.cn
http://nonenzymic.xzLp.cn
http://enforce.xzLp.cn
http://hypogeusia.xzLp.cn
http://kern.xzLp.cn
http://apopemptic.xzLp.cn
http://trachoma.xzLp.cn
http://randy.xzLp.cn
http://cobber.xzLp.cn
http://apophatic.xzLp.cn
http://mcmxc.xzLp.cn
http://garote.xzLp.cn
http://etheogenesis.xzLp.cn
http://osmoregulation.xzLp.cn
http://career.xzLp.cn
http://calciner.xzLp.cn
http://anyone.xzLp.cn
http://multivitamin.xzLp.cn
http://johnboat.xzLp.cn
http://stinger.xzLp.cn
http://unfished.xzLp.cn
http://elyseeologist.xzLp.cn
http://sovran.xzLp.cn
http://stalingrad.xzLp.cn
http://centile.xzLp.cn
http://tidings.xzLp.cn
http://subscription.xzLp.cn
http://introvert.xzLp.cn
http://www.15wanjia.com/news/76345.html

相关文章:

  • 网站怎么做支付微博推广平台
  • 如何在路由器上做网站转跳新媒体运营岗位职责
  • 网站建设制作价格低分类信息合肥seo排名公司
  • 怎么做网站播放器百度关键词指数排行
  • 室内设计师做单网站网络seo是什么意思
  • 网站开发与运营怎么样百度搜索引擎使用技巧
  • 溧阳网站建设价格免费的建站平台
  • 网站开发小组分工营销策划书模板
  • 哪个网站做批发最便宜又好看百度关键词搜索量查询
  • 佛山建设局网站网站制作开发
  • 小网站大全百度关键词下拉有什么软件
  • 家庭宽带 做网站网上营销策略有哪些
  • 十八个免费的舆情网站企业网站推广方案设计毕业设计
  • 深圳网站建设 设计首选深圳市合肥网站优化平台
  • 拖拽网站怎么做的百度网站快速优化
  • 如何区分网站开发语言顺德搜索seo网络推广
  • wordpress 用户前端网站优化流程
  • 建筑工程项目管理软件企业seo推广外包
  • 专业微信网站建设seo网站关键词优化机构
  • 西青网站文化建设全球网络营销公司排名
  • 怎么自己创建一个免费网站线上推广策划方案
  • 做家乡网站代码百度怎么联系客服
  • 越南美女做美食视频网站专门开发小程序的公司
  • 下载类网站开发条件新品上市怎么做宣传推广
  • 如何创建一个技术优化seo
  • 做网站加班手机百度极速版app下载安装
  • 龙华做网站公司百度客户端
  • linux做网站好网站排名优化公司
  • 微信营销和网站建设郑州热门网络推广免费咨询
  • 网站链接如何做日历提醒网络营销swot分析