PDA

View Full Version : string qt Qml



mouni
29th September 2016, 06:17
i want to pass Qstring from c++ file to Qml how i can give

class file....



#ifndef MYDEVICE_H
#define MYDEVICE_H

#include <QObject>
#include <QScreen>
#include <QtGui/QGuiApplication>
#include <QQmlApplicationEngine>
#ifdef Q_OS_ANDROID
#include <QtAndroidExtras>
#endif

//#include <QTcpSocket>
#include <QUdpSocket>


class MyDevice : public QObject
{
Q_OBJECT



public:
explicit MyDevice(QObject *parent = 0);
~MyDevice();


private:
bool m_isMobile;
QScreen *m_screen;
int m_dpi;
qreal m_dp;
// QTcpSocket * socket;
QUdpSocket *socket;
QByteArray m_bWriteArray;
QByteArray m_bReadArray;
const char *m_np1;
QStringList myStringList;
QString m_sdatastring;
QString m_srequestString;

public slots:
void connected();
void disconnected();
void hostFound();
void bytesWritten(qint64 bytes);
void readyRead();
void error(QAbstractSocket::SocketError socketError);
};

#endif // MYSCREEN_H

m_bWriteArray variable to xml....


Qml code


XmlListModel
{
id: model
source:"qrc:/Sample_BCID_INFO.xml" // here i want to give QString here
query: "/BCINFO/BC"
XmlRole
{
name: "LABEL";
query: "LABEL/string()"
}
}
ListView
{
id: listViewMenu
anchors.top: logoWtapper.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
clip: true
model: model
delegate: componentDelegate
}

instead of ths "qrc:/Sample_BCID_INFO.xml" i want to give m_sdatastring

anda_skoa
29th September 2016, 09:58
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,
_

mouni
29th September 2016, 13:12
functions are acessable but variables are not acessable....

anda_skoa
29th September 2016, 17:09
Hence the Q_PROPERTY to make them accessible

Cheers,
_