Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for MCUs
  4. std::string passed from c++ to qml is not set properly
QtWS25 Last Chance

std::string passed from c++ to qml is not set properly

Scheduled Pinned Locked Moved Unsolved Qt for MCUs
qulqmlqtformcu
6 Posts 3 Posters 962 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.
  • P Offline
    P Offline
    PradeepChinnasamy
    wrote on last edited by PradeepChinnasamy
    #1

    Hello,

    I am trying to set a std::string to a text in qml, the first character always shows as junk character as.
    c5e7491f-ae83-4603-a93e-395a270a7c03-image.png
    reference code used :
    Bt.h

    class Bt : public Qul::Singleton<Bt>
    {
    public:
          Qul::Property<std::string> d;
    };
    

    sample.qml

    import QtQuick 2.0
    import QtQuickUltralite.Extras 2.0
    
    Rectangle {
        id: root
        property string k:  Bt.d;
        Text {
            id: strname
            text: k
        }
    }
    

    and the string value is set from main.cpp as Bt::instance().d.setValue("yes");
    Why the first character is always junk? how to fix this?

    I am using qtformcu v2.1.0 in windows10.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Qt for MCUs being a commercial only distribution of Qt, you may have to wait a bit longer before getting an answer. In between:
      What happens if you use QString instead of std::string ?
      What happens if you append Bt.d to as string ?
      What happens if you set your Text object text property directly to Bt.d ?

      Where do you setup your Bt singleton ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PradeepChinnasamy
        wrote on last edited by
        #3

        Hi,

        What happens if you use QString instead of std::string ? - I guess QString is not available in QtforMCU.

        What happens if you append Bt.d to as string ? - If I append Bt.d in sample.qml i.e; hardcoded like Bt.d = "test"; the text is displayed without any junk character.

        What happens if you set your Text object text property directly to Bt.d ? -it is same result, first character is junk.

        Where do you setup your Bt singleton ? - All files in a same folder.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          My last question was: how do you set it up in your code ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply
          0
          • SGaistS SGaist

            My last question was: how do you set it up in your code ?

            P Offline
            P Offline
            PradeepChinnasamy
            wrote on last edited by
            #5

            @SGaist I am not sure what exactly "how do you set it up in your code ?" means, but if it is about creating instance of Bt singleton, this will be created by qul in generated code, so this global instance can be accessed anywhere in the code. Or if it is about set the value for Bt.d it is like

            Bt::instance().d.setValue("yes");
            

            as mentioned in my post.

            M 1 Reply Last reply
            0
            • P PradeepChinnasamy

              @SGaist I am not sure what exactly "how do you set it up in your code ?" means, but if it is about creating instance of Bt singleton, this will be created by qul in generated code, so this global instance can be accessed anywhere in the code. Or if it is about set the value for Bt.d it is like

              Bt::instance().d.setValue("yes");
              

              as mentioned in my post.

              M Offline
              M Offline
              Mr_Gruber
              wrote on last edited by
              #6

              @PradeepChinnasamy

              See https://doc.qt.io/QtForMCUs-2.3/qtul-fonts.html#rendering-dynamic-strings-in-qml

              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