Results 1 to 4 of 4

Thread: string qt Qml

  1. #1
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default string qt Qml

    i want to pass Qstring from c++ file to Qml how i can give

    class file....

    Qt Code:
    1. #ifndef MYDEVICE_H
    2. #define MYDEVICE_H
    3.  
    4. #include <QObject>
    5. #include <QScreen>
    6. #include <QtGui/QGuiApplication>
    7. #include <QQmlApplicationEngine>
    8. #ifdef Q_OS_ANDROID
    9. #include <QtAndroidExtras>
    10. #endif
    11.  
    12. //#include <QTcpSocket>
    13. #include <QUdpSocket>
    14.  
    15.  
    16. class MyDevice : public QObject
    17. {
    18. Q_OBJECT
    19.  
    20.  
    21.  
    22. public:
    23. explicit MyDevice(QObject *parent = 0);
    24. ~MyDevice();
    25.  
    26.  
    27. private:
    28. bool m_isMobile;
    29. QScreen *m_screen;
    30. int m_dpi;
    31. qreal m_dp;
    32. // QTcpSocket * socket;
    33. QUdpSocket *socket;
    34. QByteArray m_bWriteArray;
    35. QByteArray m_bReadArray;
    36. const char *m_np1;
    37. QStringList myStringList;
    38. QString m_sdatastring;
    39. QString m_srequestString;
    40.  
    41. public slots:
    42. void connected();
    43. void disconnected();
    44. void hostFound();
    45. void bytesWritten(qint64 bytes);
    46. void readyRead();
    47. void error(QAbstractSocket::SocketError socketError);
    48. };
    49.  
    50. #endif // MYSCREEN_H
    To copy to clipboard, switch view to plain text mode 
    m_bWriteArray variable to xml....


    Qml code
    Qt Code:
    1. XmlListModel
    2. {
    3. id: model
    4. source:"qrc:/Sample_BCID_INFO.xml" // here i want to give QString here
    5. query: "/BCINFO/BC"
    6. XmlRole
    7. {
    8. name: "LABEL";
    9. query: "LABEL/string()"
    10. }
    11. }
    12. ListView
    13. {
    14. id: listViewMenu
    15. anchors.top: logoWtapper.bottom
    16. anchors.left: parent.left
    17. anchors.right: parent.right
    18. anchors.bottom: parent.bottom
    19. clip: true
    20. model: model
    21. delegate: componentDelegate
    22. }
    To copy to clipboard, switch view to plain text mode 
    instead of ths "qrc:/Sample_BCID_INFO.xml" i want to give m_sdatastring
    Last edited by anda_skoa; 29th September 2016 at 09:55. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: string qt Qml

    You need to use the XmlListModel's "xml" property for string based content, "source" needs an URL.

    If you have access to a MyDevice object from QML then the easiest way to get access to the m_sdatastring member is to add a Q_PROPERTY using the MEMBER access variation.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: string qt Qml

    functions are acessable but variables are not acessable....

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: string qt Qml

    Hence the Q_PROPERTY to make them accessible

    Cheers,
    _

Similar Threads

  1. String Manipulation and string functions
    By Snaidy in forum Newbie
    Replies: 2
    Last Post: 26th August 2016, 11:49
  2. Replies: 3
    Last Post: 8th June 2011, 06:36
  3. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51
  4. Int to String - manipulating string
    By mickey in forum General Programming
    Replies: 6
    Last Post: 5th November 2007, 20:11
  5. String value
    By Gayathri in forum Newbie
    Replies: 2
    Last Post: 21st November 2006, 05:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.