I try to make TelnetClient.I use FileIO for read Telnet.There is no problem read or write and also create a string list but I need to show QStringList to ListView but I m getting error: "m_model is not defined".
I create QStringList:
QStringList FileIO::read() { if (m_source.isEmpty()) { emit error("source is empty"); return QStringList(); } QFile file(m_source); QString fileContent; QString line; QStringList list; if ( file.open(QIODevice::ReadWrite) ) { QTextStream t( &file ); line = t.readAll(); fileContent += line; list.append(line.split("\r\n")); foreach (QString item, list) { if (item[0].isNumber()) { list2.append(item); } } QQmlContext *ctxt; ctxt->setContextProperty("m_model", QVariant::fromValue(list2)); qDebug() << "\r\n\r\nlist2 =" << list2; line = t.readAll(); qDebug() << "SOURCE" << m_source; file.close(); } else { emit error("Unable to open the file"); return QStringList(); } return list2; This can make a new QStringList successfully and also I assign my string list as a model; m_model.
ListView { id: listView1 x: 0 y: 0 model: m_model delegate: Rectangle{ Text {text: modelData } } } and here is my ListView. When I try like this, I m getting error. How can I solve this problem. If I can use "list2" in main.cpp I can solve the problem but I don't know how can I use it in main.cpp because it exist in another class.
Thank you!
QQmlContext *ctxt; ctxt->setContextProperty("m_model", QVariant::fromValue(list2));You even doesn't create ctxt object. The program should crash at this step. Despite the fact that you have no qml engine no context at all. This link can help you too.