Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Call function in ui.qml!

Call function in ui.qml!

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 681 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hesam
    wrote on last edited by
    #1

    Please help me!
    how can i call a c++ function in ui.qml file?!

    ODБOïO 1 Reply Last reply
    0
    • H Hesam

      Please help me!
      how can i call a c++ function in ui.qml file?!

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      hi @Hesam you can't, functions are not supported in ui forms. https://doc.qt.io/qtcreator/creator-quick-ui-forms.html#javascript-functions
      Why do you need to call a function in the .ui.qml ? Why not call it in the component (.qml)

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hesam
        wrote on last edited by
        #3

        thank you for your response
        I started a project on Qt Design Studio and then convert it into a Quick project
        Now the only files I have are ui.qml files
        Now I need to call the signals from the c ++ files
        this is my question: how can i call c++ function when i clicked on a shape in ui.qml file?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Muddassir
          wrote last edited by
          #4

          To call CPP function in Screen1.ui.qml ... im renaming file name to Screen1.qml ... is it proper way to call functions?

          @ODБOï could you provide guidance how can we call functions in the component(.qml)... e.g. i need to call function when button clicked.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kaixoo
            wrote last edited by
            #5

            You need to create a model with Q_INVOKABLE function:

            class MyModel : public QObject {
              Q_OBJECT
              QML_ELEMENT
            
              MyModel() = default;
              ~MyModel() = default;
            
            public:
              Q_INVOKABLE void doSomething();
            };
            

            Then add it to your QML Widget:

            import Your.App.Namespace
            
            Item {
              MyModel { id: myModel }
            }
            
            

            Then you can use myModel.doSomething().

            Maybe read the QML documentation or contribute to a QML project to see how it works? I learnt all this while forking MuseScore.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved