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. 'pure' C++ and QML
Forum Updated to NodeBB v4.3 + New Features

'pure' C++ and QML

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 2.3k 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.
  • B Offline
    B Offline
    Burza
    wrote on last edited by
    #1

    Hello,

    About year ago I learned (on my own) C++ and managed to complete my goal application - console app taking optional switches to control input/output.

    Next goal was to learn GUI and that's where it became harder.
    Keep in mind that I am self learner and probably approaching learning curve from other end that it would be suggested, i.e. I had goals and was searching methods how to achieve those goals.

    After some searching of best approach I decided that QML is the best approach for me. Particularly I liked that I could use QML and JS for interface and combine it with C++ used for backend. Sounded perfect!

    I started learning QML (most helpful was http://qmlbook.org) and I made 'perfect' GUI.

    Now I'm trying to combine my C++ code with QML and that's where I hit the wall.
    It seems like I need to completely rewrite my existing 'pure' C++ code to Qt C++ in order to be able to use it...
    Is that right?

    Are there any methods to use 'pure' C++ classes/functions instead of learning Qt C++ ?
    Please direct me to easiest/best ways to do it.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dmitry.Sokolov
      wrote on last edited by
      #2

      You mean you want to call that pure C++ classes/functions from QML GUI, right?

      If so, you can write a "facade class":http://en.wikipedia.org/wiki/Facade_pattern derived from QObject and expose it to QML with registerXXX function.

      Pure C++ class has no the Qt Meta-Object System and can not be used in QML.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Burza
        wrote on last edited by
        #3

        Thanks, will have a look into that.
        However as for a noob like me that looks very complicated ;)

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fxam
          wrote on last edited by
          #4

          It would be better if you add Qt spices into your 'pure' C++ to integrate with QML, rather than introducing another layer of facade/adapter. I believe you don't want to keep writing that extra layer in your future projects.

          You can still keep your methods and logic but of course some modifications are need, like:

          inheriting your class from QObject

          change some 'pure' data type into Qt's flavor, eg: change your existing string to QString.

          make some methods become Qt slots so that Javascript in QML can call them

          You can check out the WeatherInfo example which illustrates the integration of C++ and QML: http://qt-project.org/doc/qt-5/qtpositioning-weatherinfo-example.html

          You should have a good read on "Integrating QML and C++":http://qt-project.org/doc/qt-5/qtqml-cppintegration-topic.html too.

          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