{"id":22399111,"url":"https://github.com/JayTwoLab/qml-bind","last_synced_at":"2025-07-31T13:32:46.586Z","repository":{"id":96143194,"uuid":"196927124","full_name":"j2doll/qml-bind","owner":"j2doll","description":"QML binding example for personal purpose.","archived":false,"fork":false,"pushed_at":"2021-03-07T12:26:15.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-26T23:46:43.777Z","etag":null,"topics":["bind","cpp","example","qml","qt","qtquick"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/j2doll.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-15T05:02:30.000Z","updated_at":"2024-05-22T09:40:49.000Z","dependencies_parsed_at":"2023-04-04T15:32:35.690Z","dependency_job_id":null,"html_url":"https://github.com/j2doll/qml-bind","commit_stats":null,"previous_names":["j2doll/qml-bind"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2doll%2Fqml-bind","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2doll%2Fqml-bind/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2doll%2Fqml-bind/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2doll%2Fqml-bind/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/j2doll","download_url":"https://codeload.github.com/j2doll/qml-bind/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228249346,"owners_count":17891461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bind","cpp","example","qml","qt","qtquick"],"created_at":"2024-12-05T07:13:25.070Z","updated_at":"2025-07-31T13:32:41.310Z","avatar_url":"https://github.com/j2doll.png","language":"C++","readme":"# QML binding example\n\n## Example\n\n- See [bind](bind/) example.\n\n1. set QML properties in C++.\n\t\n```cpp\n    int rootObjSize = engine.rootObjects().size();\n    for ( int ic = 0; ic \u003c rootObjSize ; ic++ )\n    {\n        QObject* obj = engine.rootObjects().at( ic );\n        if ( obj == nullptr )\n            continue;\n\t\t\t\n        // [3] find the root object that has 'objectName'. 'objectName' is 'mainWindow'.\n        QVariant val = obj-\u003eproperty( \"objectName\" );\n        if ( false == val.isNull() \u0026\u0026\n             val.toString() == QString(\"mainWindow\") )\n        {\n            // [4] success to find 'mainWindow'\n            QObject* mainWindowObj = obj;\n            mainWindowObj-\u003esetProperty( \"title\", QVariant(QString(\"HELLO WORLD\")) ); // change 'title' of 'mainWindow'\n\t\t\t\n            // [5] find child object. which objectName is 'mainText'.\n            QObject *textObj = mainWindowObj-\u003efindChild\u003cQObject*\u003e( \"mainText\" );\n            if ( textObj != nullptr )\n            {\n                qmlTimer-\u003eobjText = textObj;\n\n                // [6] get 'x' from 'mainText'\n                QVariant valX = textObj-\u003eproperty( \"x\" );\n                qDebug() \u003c\u003c \"x : \" \u003c\u003c valX;\n            }\t\t\t\n```\t\n\t\n2. get C++ properties in QML\n\n```cpp\n    // [1] set context\n    CppValue* cppValue1 = new CppValue( \u0026app );\n    engine.rootContext()-\u003esetContextProperty( \"cppValue1\", cppValue1 );\n```\n\n```cpp\nclass CppValue : public QObject\n{\n    Q_OBJECT\n    Q_PROPERTY( QString strCppValue READ getStrCppValue )\npublic:\n    explicit CppValue(QObject *parent = nullptr);\n    QString getStrCppValue();\n    Q_INVOKABLE QString testCalling(QString param) const;\nprotected:\n    QString m_strCppValue;\nsignals:\npublic slots:\n};\n```\n\t\n```qml\n            // [2] get property of C++ 'cppValue1'\n            var tempValue = cppValue1.strCppValue;\n            console.log( tempValue ); // CppValue : (random number that is made by constructor)\n```\t\n\t\n3. call C++ function in QML\n\t\n```qml\n    Button { // our Button component\n        id: button\n        x: 250; y: 12\n        text: \"Push me\"\n        onClicked: {\n            // [1] call function\n            var testParam = \"COOL\";\n            var tempResult = cppValue1.testCalling( testParam ); // call 'testCalling' of C++ 'cppValue1'\n            console.log( tempResult ); //  tc: COOL, (random number)\n```\n\n## License\n\n- MIT License\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJayTwoLab%2Fqml-bind","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJayTwoLab%2Fqml-bind","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJayTwoLab%2Fqml-bind/lists"}