Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Only one element os a QStringList in a ListView

$
0
0
hi, people. I’m playing with the SDDM [github.com], trying to show the session’s list in a dropdown menu instead of a spinbox, but only one element of the list appear in the List View, and i can’t realize why the full list is not being loaded. The only loaded is the custom. Changing the current index of of List View is possible load any, but not all sessions. Anyone can help? The code snippets: The QStringList is exposed as a property class SessionManager : public QObject { Q_OBJECT Q_PROPERTY(QStringList sessionNames READ sessionNames CONSTANT) and is populated at line 30     SessionManager::SessionManager() : d(new SessionManagerPrivate()) {         // read session files         QDir dir(Configuration::instance()->sessionsDir());         dir.setNameFilters(QStringList() << "*.desktop");         dir.setFilter(QDir::Files);         // read session         foreach (const QString &session, dir.entryList()) {             QFile inputFile(dir.absoluteFilePath(session));             if (!inputFile.open(QIODevice::ReadOnly))                 continue;             SessionInfo si { session, "", "", "" };             QTextStream in(&inputFile);             while (!in.atEnd()) {                 QString line = in.readLine();                 if (line.startsWith("Name="))                     si.name = line.mid(5);                 if (line.startsWith("Exec="))                     si.exec = line.mid(5);                 if (line.startsWith("Comment="))                     si.comment = line.mid(8);             }             // add to sessions list             d->sessions.push_back(si);             // close file             inputFile.close();         }         // check last session index         d->lastSessionIndex = 0;         for (int i = 0; i < d->sessions.size(); ++i) {             d->sessionNames << d->sessions.at(i).name;             if (d->sessions.at(i).file == Configuration::instance()->lastSession())                 d->lastSessionIndex = i;         } The property is exposed to QML SessionManager sessionManager; view.rootContext()->setContextProperty("sessionNames", QVariant::fromValue(sessionManager.sessionNames())); Recived in Main.qml and sent to SpinBox.qml SpinBox {       items: sessionNames recived in SpinBox.qml and used FocusScope {     id: container     property variant items: [""] [...]     ListView {          id: listView          model: items          delegate: Text {                text: modelData          }      } }

Viewing all articles
Browse latest Browse all 4972

Trending Articles