Forums

OverviewFelgo 2 Support (Qt 5) › can't integrate C++ in qml

Tagged: , ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #21224

    Felgo User

    Hi,

    I have a problem when i want to integrate C++ class in my qml the debugger say that “ravupModuleLogIn 1.0” my module is not installed…

    c++ code:

    Client::instance(m_application);
    
        QQmlApplicationEngine engine;
        m_felgo->setPreservePlatformFonts(true);
        m_felgo->initialize(&engine);
        m_felgo->setMainQmlFileName(QStringLiteral("qml/Main.qml"));
    
        qmlRegisterType<LogInModule>("ravupModuleLogIn", 1, 0, "logIn");
        m_engine->load(QUrl(m_felgo->mainQmlFileName()));
    
        // to start your project as Live Client, comment (remove) the lines "felgo.setMainQmlFileName ..." & "engine.load ...",
        // and uncomment the line below
        //FelgoLiveClient client (&engine);
    
        if (m_engine->rootObjects().isEmpty())
            exit(-1);

     

    qml code:

    import QtQuick.Window 2.2
    import QtQuick.Controls 2.0
    import QtQuick.Controls.Styles 1.4
    import Felgo 3.0
    import QtQuick 2.0
    import QtQuick.Layouts 1.1
    import ravupModuleLogIn 1.0
    
    Page {
        id: loginPage
    
        Rectangle {
            id: headBar
            width: parent.width
            height: parent.height / 10
            anchors.top: parent.top
            color: "#ff5722"
        }
    
        Image {
            id: logo
            source: "../../assets/logo.png"
            width: parent.width / 2
            height: parent.height / 3
            anchors.left: parent.left
            anchors.leftMargin: (parent.width - width) / 2
            anchors.top: headBar.bottom
            anchors.bottomMargin: 0
            fillMode: Image.PreserveAspectFit
        }
    
        GridLayout {
            id: content
            anchors.top: logo.bottom
            anchors.left: parent.left
            anchors.leftMargin: (parent.width - width) / 2
            columnSpacing: dp(20)
            rowSpacing: dp(40)
            columns: 2
    
            // email text and field
            AppText {
                text: qsTr("E-mail")
                font.pixelSize: sp(12)
            }
    
            AppTextField {
                id: txtUsername
                Layout.preferredWidth: dp(200)
                showClearButton: true
                font.pixelSize: sp(14)
                borderColor: Theme.tintColor
                borderWidth: dp(1)
                onTextChanged: logIn.setUsername(txtUsername.text)
            }
    
            // password text and field
            AppText {
                text: qsTr("Password")
                font.pixelSize: sp(12)
            }
    
            AppTextField {
                id: txtPassword
                Layout.preferredWidth: dp(200)
                showClearButton: true
                font.pixelSize: sp(14)
                borderColor: Theme.tintColor
                borderWidth: dp(1)
                echoMode: TextInput.Password
                onTextChanged: logIn.setPassword(txtPassword.text)
            }
    
            // column for buttons, we use column here to avoid additional spacing between buttons
            Column {
                Layout.fillWidth: true
                Layout.columnSpan: 2
                Layout.topMargin: dp(0)
    
                // buttons
                AppButton {
                    text: qsTr("Login")
                    flat: false
                    anchors.horizontalCenter: parent.horizontalCenter
                    onClicked: {
                        loginPage.forceActiveFocus() // move focus away from text fields
    
                        // call login action
                        logIn.login()
                    }
                }
    
                AppButton {
                    text: qsTr("No account yet? Register now")
                    flat: true
                    anchors.horizontalCenter: parent.horizontalCenter
                    onClicked: {
                        loginPage.forceActiveFocus() // move focus away from text fields
    
                        // call your logic action to register here
                        console.debug("registering...")
                    }
                }
            }
        }
    }
    

     

    #21225

    Günther
    Felgo Team

    Hi,

    I assume you are using Felgo Live to preview your app during development?

    ​The default Live Client can only reload and show changed QML code, but not compiled C++ code of your project. To use your custom a C++ modules together with Felgo Live, it is required to compile your app into an own Live Client for your project. Please follow this guide for more information: https://v-play.net/updates/release-2-16-1-live-code-reloading-with-custom-c-and-native-code-for-qt

    Hope this helps!

    #21227

    Felgo User

    thanks for your response but I have already follow this tutorial and the problem is that the tutorial use an old version of felgo (V-Play) and now it’s  Felgo 3.1…

    do you have more detail or more precision about the procedure with Felgo 3.1

    #21228

    Felgo User

    I have exactly the same problem.

    I try to follow the tutorial but the problem persist.

    #21229

    Günther
    Felgo Team

    The steps of the guide are still working with Felgo but configuration variables and class names that contained “V-Play” are now renamed for “Felgo”. You can also have a look at the Cpp Integration Example in your Felgo SDK under <Felgo-SDK-Folder>/examples/Felgo/appdemos/cpp-qml-integration.

    By default, the Live Client will show “file:Cpp-qml-integration//qml/Main.qml:6: module “com.yourcompany.xyz” is not installed” for this project. (as the Cpp module does not get compiled with Felgo Live).

    By pressing the green run button in Qt Creator, you can build the app for the selected platform. The Cpp code gets compiled then and the application executes without issues. To build an own Live Client that includes your Cpp code, uncomment the following line in the pro file:

    # uncomment this line to add the Live Client Module and use live reloading with your custom C++ code
    CONFIG += felgo-live

    Then uncomment the FelgoLiveClient include in your main.cpp

    // uncomment this line to add the Live Client Module and use live reloading with your custom C++ code
    #include <FelgoLiveClient>
    

    Then comment the engine.load call and uncomment the FelgoLiveClient initialization:

      // engine.load(QUrl(felgo.mainQmlFileName()));
    
      // to start your project as Live Client, comment (remove) the lines "felgo.setMainQmlFileName ..." & "engine.load ...",
      // and uncomment the line below
      FelgoLiveClient client (&engine);

    If you now build the app with the green run button in Qt Creator, you get a custom Live Client, which you can connect to the Felgo Live Server (press connect and accept the request with the Live Server). With this custom live client app, the above error also no longer shows up. To use the custom Live Client on mobile, you can build the app with the Felgo for iOS or Felgo for Android Build Kits, instead of Felgo Desktop.

    Hope this helps!

     

    #21230

    Felgo User

    thanks gunther it’s work

    you’re my god!!!

    #22053

    User

    I’m having issues with this even after following the above.

    Getting error: cannot find -Lc++

    and linker command failed with exit code 1 (use -v to see invocation)

Viewing 7 posts - 1 through 7 (of 7 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support