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. QML/C++ application

QML/C++ application

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 485 Views
  • 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.
  • F Offline
    F Offline
    fender
    wrote on last edited by
    #1

    Good afternoon.
    Now my application is written in MainWindow + C ++.
    I plan to rewrite the design on QML. And as is known with ++ and QML works through Q_INVOKABLE / Q_PROPERTY
    So: now I have the calculation functions, the values ​​of variables are taken from doublespinbox
    How to properly implement this on QML / C ++?

        const int size= 5; // 5 вариантов
        double p_overpressure[size]= // p изб
        {
                ui->doubleSpinBox_p_overpressure_1->value(),
                ui->doubleSpinBox_p_overpressure_2->value(),
                ui->doubleSpinBox_p_overpressure_3->value(),
                ui->doubleSpinBox_p_overpressure_4->value(),
                ui->doubleSpinBox_p_overpressure_5->value()
    };
    
    double calc_V_gas(double G,
                      double V_accumulated,          // V н
                      double p_overpressure, // p изб
                      double p_saturation,   // p нас
                      double p_0)
    // (8,9)
    {
    
        if(p_overpressure>p_saturation)
            return 0;
    
        return G*V_accumulated * p_0/(p_overpressure+p_0)*
                (
                    1-0.5*(p_overpressure/p_saturation+
                           std::sqrt( 2*p_overpressure/p_saturation - std::pow(p_overpressure/p_saturation,2)))
                    );
    }
    
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sillimon
      wrote on last edited by Sillimon
      #2

      I don't really get what you really want...

      The only point with QML is to send the values in the correct format and use them in.

      There is more than one way to send it but what i prefer, personally as a rookie, is to instantiate objects in main and send it to be used in QML :

      main.cpp

          QQmlApplicationEngine engine;
      
          Reader reader;
          ReadWrite readWrite;
          CardInformation card;
      
          engine.rootContext()->setContextProperty("reader", &reader);
          engine.rootContext()->setContextProperty("readWrite", &readWrite);
          engine.rootContext()->setContextProperty("card", &card);
      

      You can now call your object reader, readWrite or card in QML.
      As a Q_INVOKABLE :

      .h
      class ReadWrite : public QObject
      {
          Q_OBJECT
      
      public:
          explicit ReadWrite(QObject *parent = nullptr);
      
          Q_INVOKABLE QString readChip();
      
          [...]
      }
      
      .cpp
      QString ReadWrite::readChip()
      {
              QString myVar = "nasdrovia";
              return myVar;
      }
      
      
      .qml
      Text
      {
             text: readWrite.readChip()
      }
      

      Or as a Q_PROPERTY :

      .h
      class Reader : public QObject
      {
          Q_OBJECT
      
          Q_PROPERTY ( int myInteger \
                     READ getMyInteger \
                     WRITE setMyInteger \
                     NOTIFY myIntegerChanged )
      
      public:
          int getMyInteger();
          void setMyInteger(int newInteger);
      
      signals:
          myIntegerChanged();
      
      private:
          int m_myInteger;
      }
      
      .cpp
      int Reader::getMyInteger
      {
          return m_myInteger;
      }
      
      void Reader::setMyInteger(int newInteger)
      {
          m_myInteger = newInteger;
          emit myIntegerChanged();
      }
      
      
      .qml
      Rectangle
      {
             id: myRectangle
      
              //Should be able to detect if it must use READ or WRITE property of the Q_PROPERTY --> here, Read
             height: reader.myInteger
      
             width: 15
      
            MouseArea
            {
                 //Here, Write
                 onClicked: reader.myInteger = myRectangle.width
            }
      }
      

      Then, the format you'll use for it is up to you, take a look at this : Data types conversion between C++ and QML

      and this : QML basic types

      Does it answer your question a bit ?

      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