Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating QQuick Items from C++
Forum Updated to NodeBB v4.3 + New Features

Creating QQuick Items from C++

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 521 Views 3 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.
  • 1 Offline
    1 Offline
    1XU7
    wrote on last edited by 1XU7
    #1

    Hi!!

    Can i make this:

    QML:

    Button {
        id: myButton
        x: 200
        y: 400
        width: 200
        height: 30
        text: "Push me"
    }
    

    ...but from C++ ?

    I mean, i'm not looking to create a QPushButton but a QQuick Button but from C++... somehow transcribe my QML document into C++ .. If so, can you show an example?

    Thanks in advance....

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      Are you trying to instantiate a QML-defined component from C++?
      QQmlComponent, which can be passed a URL to a file, or a byte array containing the source via the setData function.

      If the goal is to create the button purely from C++, there's the direct use of the scene graph APIs, or QQuickPaintedItem for an API similar to Qt widgets.

      Transcribing suggests that this involves a working program.

      If this is a performance concern, have you seen the QML profiler built into Creator? Or is this a source obfuscation situation? There is some compilation into a binary format or C++ that also helps decrease load time. I don't know the current state.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 1 Reply Last reply
      0
      • jeremy_kJ jeremy_k

        Are you trying to instantiate a QML-defined component from C++?
        QQmlComponent, which can be passed a URL to a file, or a byte array containing the source via the setData function.

        If the goal is to create the button purely from C++, there's the direct use of the scene graph APIs, or QQuickPaintedItem for an API similar to Qt widgets.

        Transcribing suggests that this involves a working program.

        If this is a performance concern, have you seen the QML profiler built into Creator? Or is this a source obfuscation situation? There is some compilation into a binary format or C++ that also helps decrease load time. I don't know the current state.

        1 Offline
        1 Offline
        1XU7
        wrote on last edited by
        #3

        @jeremy_k

        hi, QSceneGraph is what i was looking for... i preffer c++ always..
        according to what i was looking, Scene Graph is faster than PaintedItems..

        thanks.

        A 1 Reply Last reply
        0
        • 1 1XU7

          @jeremy_k

          hi, QSceneGraph is what i was looking for... i preffer c++ always..
          according to what i was looking, Scene Graph is faster than PaintedItems..

          thanks.

          A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          @1XU7 Just means doing everything from scratch. There is no "inherit from QML Button" in C++
          The learning curve is pretty steep, examples are rare.

          A Pl45m4P 2 Replies Last reply
          0
          • A Asperamanca

            @1XU7 Just means doing everything from scratch. There is no "inherit from QML Button" in C++
            The learning curve is pretty steep, examples are rare.

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            @Asperamanca Also, for UI handling from C++, you'll want to add your own event filter.

            1 Reply Last reply
            0
            • A Asperamanca

              @1XU7 Just means doing everything from scratch. There is no "inherit from QML Button" in C++
              The learning curve is pretty steep, examples are rare.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @Asperamanca

              Sounds like you tried it, but didn't like the outcome?


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              A 1 Reply Last reply
              0
              • Pl45m4P Pl45m4

                @Asperamanca

                Sounds like you tried it, but didn't like the outcome?

                A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                @Pl45m4 SceneGraph has it's uses for custom components.
                An event filter on the C++ side is useful because you can enforce common event handling rules across all components.
                Building a scene dynamically from C++ using prefabricated QML-building blocks has it's use cases.

                But I wouldn't start writing basic QML UI via C++.

                Pl45m4P 1 Reply Last reply
                0
                • A Asperamanca

                  @Pl45m4 SceneGraph has it's uses for custom components.
                  An event filter on the C++ side is useful because you can enforce common event handling rules across all components.
                  Building a scene dynamically from C++ using prefabricated QML-building blocks has it's use cases.

                  But I wouldn't start writing basic QML UI via C++.

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by
                  #8

                  @Asperamanca

                  I'm just curious, because I've never heard of it and usually you would design the QuickItems in their QMLanguage on QtQuick side and then connect your C++ code to it


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  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