Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.0k Topics 77.1k Posts
  • QML window is always empty

    Solved
    17
    0 Votes
    17 Posts
    2k Views
    KroMignonK
    @bronstein87 Your welcome
  • QML FileDialog - set quantity limit on files to select

    Solved
    2
    0 Votes
    2 Posts
    204 Views
    JonBJ
    @MikhailG I'm going to stick my neck and suggest there will not be any such facility.
  • QML qsTr() translation doesn't translate if text is passed in from other files

    Unsolved
    4
    0 Votes
    4 Posts
    2k Views
    R
    Maybe you can use qsTranslate() instead of qsTr() to define the context ? At least that was useful for me since the value to translate was passed by another QML file translateStr = qsTr("TrContext", "hello")
  • QT QUICK request API REST

    Unsolved
    4
    0 Votes
    4 Posts
    419 Views
    6thC6
    As @daljit97 - I came here to say this too - do processing out of the GUI. Just for your own exposure - there is plenty of other kinds of networking examples too like: https://doc.qt.io/qt-5/qtnetwork-torrent-example.html More @ https://doc.qt.io/qt-5/qtnetwork-index.html https://doc.qt.io/qt-5/qudpsocket.html https://doc.qt.io/qt-5/qtcpsocket.html https://doc.qt.io/qt-5/qsslsocket.html https://doc.qt.io/qt-5/qsctpsocket.html etc Again, I'd highly encourage to disconnect anything not GUI into c++ and pass signals of only the data you care for on completion / event signals. It just keeps gui maintainable and cleanly separated from functionality.
  • Best practice for a small team to work on a Qt Quick project?

    Unsolved share experience best practice
    3
    0 Votes
    3 Posts
    823 Views
    jeanmilostJ
    @sierdzio thank you for sharing your experience. An important point for our development team is to allow the designers to write a part of the qml code, at least to basically create the interface as they want, or to be able to modify a part of the interface during the development cycle without having to resort to developers. I must clarify that they have the skills to achieve that. We also have the possibility to reload any modified qml file on runtime from inside our apps, so the modifications may be shown directly into the running application. So, what I'm searching for is a framework or IDE which would allow to write qml code in the most possible independent way. Until now the closest tools I found were Qt Creator and Qt Design Studio, but Qt Creator is problematic when the qml code links to custom c++ widgets or references (especially when the code is created with Visual Studio), whereas Qt Design Studio allows to create a pure qml interface, but needs to be converted before using it in a real c++ project. 2 questions interest me: Are there any other tools than the 2 mentioned above to generate qml content? How other development teams manage the change cycles between the design teams and the programming teams?
  • Bug with Qt 5.15 beta 2

    Unsolved
    2
    0 Votes
    2 Posts
    209 Views
    K
    @DBoosalis You have to check with https://bugreports.qt.io/secure/Dashboard.jspa and eventually file a bug report. This forum is not monitored for eventual bug reports.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    10 Views
    No one has replied
  • GridView and ObjectModel. Highlight size and resize of dynamically added elements.

    Unsolved
    1
    0 Votes
    1 Posts
    292 Views
    No one has replied
  • shift delegate in GridView

    Unsolved
    2
    0 Votes
    2 Posts
    171 Views
    6thC6
    Not information for me to help mate. Possibly padding / margins. Really too hard basket for me (with just this). Anything is possible if you smash it with a big enough hammer. Whether it's a good idea or not... This book might actually prove more helpful than my reply though. https://qmlbook.github.io/ch07-modelview/modelview.html#dynamic-views https://qmlbook.github.io/ch07-modelview/modelview.html#shape-shifting-delegates
  • 0 Votes
    3 Posts
    713 Views
    S
    @qyvlik Thanks for the suggestion. I have tried sample project with Loader option. It looks working. Let me do the actual program and see how best it works.
  • QML XMLHttpRequest and proxy

    Unsolved
    2
    0 Votes
    2 Posts
    5k Views
    Q
    Qt version 5.13.2 QML XMLHttpRequest implement and wrapper as follow class QQmlXMLHttpRequest implement in qqmlxmlhttprequest.cpp QQmlXMLHttpRequestWrapper in qqmlxmlhttprequest.cpp The QQmlXMLHttpRequest have QNetworkAccessManager type member m_nam, set m_nam code as follow: QQmlXMLHttpRequest *r = new QQmlXMLHttpRequest(scope.engine->v8Engine->networkAccessManager(), scope.engine); You can use the api void QQmlEngine::setNetworkAccessManagerFactory(QQmlNetworkAccessManagerFactory *factory) defined you own QNetworkAccessManager. class MyNetworkAccessManager : public QNetworkAccessManager { Q_OBJECT public: MyNetworkAccessManager(QObject* parent=nullptr): QNetworkAccessManager(parent) {} protected: QNetworkReply *createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &originalReq, QIODevice *outgoingData = nullptr) { #ifdef QT_DEBUG qDebug() << Q_FUNC_INFO << "url:" << originalReq.url(); #endif // do something before request // set the cookie // set proxy // ... return this->QNetworkAccessManager::createRequest(op, originalReq, outgoingData); } }; class CacheableNetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory { public: // use by xmlhttprequest // use by qml type such Image virtual QNetworkAccessManager *create(QObject *parent) { QNetworkAccessManager *nam = new MyNetworkAccessManager(parent); // QNetworkAccessManager *nam = new QNetworkAccessManager(parent); QNetworkDiskCache* diskCache = new QNetworkDiskCache(nam); QString cachePath = QStandardPaths::displayName(QStandardPaths::AppDataLocation) + "/image-cache"; diskCache->setCacheDirectory(cachePath); diskCache->setMaximumCacheSize(100 * 1024 * 1024); // 100 MB nam->setCache(diskCache); #ifdef QT_DEBUG qDebug() << Q_FUNC_INFO << " cachePath:" << diskCache->cacheDirectory(); #endif return nam; } }; If you want use prue qml to set http proxy, try the 3rdparty library.
  • random crash of application

    Unsolved
    6
    0 Votes
    6 Posts
    797 Views
    kshegunovK
    About 70 threads to sift through, huh? I'm rather convinced you have a threading issue based on the sheer number of threads (most of which don't do anything anyway). Please take that big trace you have and remove all the threads that are blocked (i.e. these that have #0 pthread_cond_wait at the top of their stack) and then provide the filtered data. And for the love of god, please don't post it in the forum without even putting it in a code tag, upload it somewhere and post the link or something.
  • QML and js reading json file and change content "on the go"

    13
    0 Votes
    13 Posts
    15k Views
    Y
    @Xander84 said in QML and js reading json file and change content "on the go": I haven't published it yet, but I can just post the code here it isn't that much. jsonfile.h @ #ifndef JSONFILE_H #define JSONFILE_H #include <QObject> #include <QFile> #include <QVariant> class JsonFile : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString fileName READ fileName NOTIFY nameChanged) Q_PROPERTY(bool exists READ exists) Q_PROPERTY(bool writeable READ writeable) Q_PROPERTY(bool readable READ readable) Q_PROPERTY(qint64 size READ size) Q_PROPERTY(QString error READ error) public: explicit JsonFile(QObject *parent = 0); JsonFile(const QString &name, QObject *parent = 0); inline QString name(&#41; const { return m_file.fileName(); } QString fileName() const; inline bool exists() const { return m_file.exists(); } inline bool writeable() const { return m_file.permissions().testFlag(QFileDevice::WriteUser); } inline bool readable() const { return m_file.permissions().testFlag(QFileDevice::ReadUser); } inline qint64 size() const { return m_file.size(); } inline QString error() const { return m_error; } Q_INVOKABLE QString relativeFilePath(const QString &dir = QString()) const; Q_INVOKABLE bool rename(const QString &newName); Q_INVOKABLE inline bool copy(const QString &newName) { return m_file.copy(newName); } Q_INVOKABLE inline bool remove() { return m_file.remove(); } Q_INVOKABLE bool write(const QVariant &data); Q_INVOKABLE QVariant read(); signals: void nameChanged(const QString &name); public slots: void setName(const QString &name); private: QFile m_file; QString m_error; }; #endif // JSONFILE_H @ jsonfile.cpp @ #include "jsonfile.h" #include <QUrl> #include <QFileInfo> #include <QDir> #include <QJsonDocument> JsonFile::JsonFile(QObject *parent) : QObject(parent) { } JsonFile::JsonFile(const QString &name, QObject *parent) : QObject(parent), m_file(name) { } void JsonFile::setName(const QString &name) { // fix to convert URL's to local file names QUrl url(name); QString localName = url.isLocalFile() ? url.toLocalFile() : name; if (m_file.fileName() != localName) { m_file.setFileName(localName); emit nameChanged(localName); } } QString JsonFile::fileName() const { return QFileInfo(m_file).fileName(); } QString JsonFile::relativeFilePath(const QString &dir) const { return QDir(dir).relativeFilePath(m_file.fileName()); } bool JsonFile::rename(const QString &newName) { bool success = m_file.rename(newName); if (success) { emit nameChanged(newName); } return success; } bool JsonFile::write(const QVariant &data) { if (m_file.fileName().isEmpty()) { m_error = tr("empty name"); return false; } QJsonDocument doc = QJsonDocument::fromVariant(data); if (doc.isNull()) { m_error = tr("cannot convert '%1' to JSON document").arg(data.typeName()); return false; } if (doc.isEmpty()) { m_error = tr("empty data"); return false; } QByteArray json = doc.toJson(); if (!m_file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { m_error = tr("cannot open file '%1' for writing: %2") .arg(m_file.fileName()).arg((m_file.errorString())); return false; } bool success = m_file.write(json) == json.size(); m_file.close(); return success; } QVariant JsonFile::read() { if (m_file.fileName().isEmpty()) { m_error = tr("empty name"); return QVariant(); } if (!m_file.open(QIODevice::ReadOnly | QIODevice::Text)) { m_error = tr("cannot open file '%1' for reading: %2") .arg(m_file.fileName()).arg((m_file.errorString())); return QVariant(); } QByteArray json = m_file.readAll(); m_file.close(); QJsonParseError error; QJsonDocument doc = QJsonDocument::fromJson(json, &error); if (error.error != QJsonParseError::NoError) { m_error = tr("invalid JSON file '%1' at offset %2") .arg(error.errorString()).arg(error.offset); return QVariant(); } return doc.toVariant(); } @ just register that class in the QML engine, like always in main.cpp or where you do that. @ qmlRegisterType<JsonFile>("JsonFile", 1, 0, "JsonFile"); @ I think that class should be fairly easy to understand, don't get scared by the amount f properties and methods, most of them are just helper functions as you can see :) if any error happens (file not found while reading, invalid JSON content, etc) the error message will be available through the "error" property. Hope that helps :) which version of qt used for this code? i tried use that, but received 2 errors: @ inline QString name() const { return m_file.fileName(); } /home/isaac/projetos/estudo/teste_tr/jsonfile.h:23: error: C++ requires a type specifier for all declarations @ @ QString JsonFile::fileName() const /home/isaac/projetos/estudo/teste_tr/jsonfile.cpp:29: error: out-of-line definition of 'fileName' does not match any declaration in 'JsonFile' @ I'm using 5.14.1
  • integrating with QAbstractListModel

    Unsolved signal & slot listview
    1
    0 Votes
    1 Posts
    360 Views
    No one has replied
  • Qml sample project do not work on iOS simulator (mac)

    Solved
    2
    0 Votes
    2 Posts
    210 Views
    M
    So It seems that there is a bug with Qt 5.14.1 version on mac. I found this bug report here: https://bugreports.qt.io/browse/QTBUG-81699 The simple solution is to use Qt 5.14
  • 0 Votes
    2 Posts
    1k Views
    H
    Alright after some research I probably found a workaround to fix this. I got help and inspiration here. The problem is that sometimes when the elements are stored in containers such as ScrollView the z-order thing doesn't work well plus the container can catch mouse event not allowing it to propagate to the helper MouseArea. In such cases all the problematic elements need to contain TapHandler which allows to catch the click event and do custom action. So for example: ScrollView { TapHandler { onTapped: outFocuser.forceActiveFocus();} } In this way no z-order tricks are needed nor the onActiveFocusChanged property in TextArea.
  • TextField editing allowed only after entering a PIN

    Unsolved
    1
    0 Votes
    1 Posts
    114 Views
    No one has replied
  • module "QtQuick.Controls" version 2.2 is not installed

    Unsolved
    9
    0 Votes
    9 Posts
    26k Views
    A
    Bug fix for Debian 10 and default Qt5.11: sudo apt install qml-module-qtquick-controls2
  • How to custom cells position in QML GridView?

    Unsolved
    2
    0 Votes
    2 Posts
    455 Views
    MarkkyboyM
    Hi Dylan, I'm still learning QML, so my answer here may not be the best solution but it works, this is how I'd do it; import QtQuick 2.12 import QtQuick.Window 2.12 Window { visible: true width: 400 height: 300 color: "#5b9bd5" title: qsTr("Hello World") Column { y: 30 id: column spacing: 20 width: parent.width Row { spacing: 20; anchors.horizontalCenter: parent.horizontalCenter Rectangle { color: "#ed7d31"; width: 100; height: 60; radius: 10 Text { text: "1"; color: "white"; anchors.centerIn: parent } } Rectangle { color: "#ed7d31"; width: 100; height: 60; radius: 10 Text { text: "2"; color: "white";anchors.centerIn: parent } } Rectangle { color: "#ed7d31"; width: 100; height: 60; radius: 10 Text { text: "3"; color: "white";anchors.centerIn: parent } } } Row { spacing: 20; anchors.horizontalCenter: parent.horizontalCenter Rectangle { color: "#ed7d31"; width: 100; height: 60; radius: 10 Text { text: "4"; color: "white"; anchors.centerIn: parent } } Rectangle { color: "#ed7d31"; width: 100; height: 60; radius: 10 Text { text: "5"; color: "white"; anchors.centerIn: parent } } Rectangle { color: "#ed7d31"; width: 100; height: 60; radius: 10 Text { text: "6"; color: "white"; anchors.centerIn: parent } } } Row { spacing: 20; anchors.horizontalCenter: parent.horizontalCenter Rectangle { color: "#ed7d31"; width: 100; height: 60; radius: 10 Text { text: "7"; color: "white"; anchors.centerIn: parent } } Rectangle { color: "#ed7d31"; width: 100; height: 60; radius: 10 Text { text: "8"; color: "white"; anchors.centerIn: parent } } } } } [image: d947122e-522a-4c7b-a1df-9bf69a5a9a37.JPG]
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    6 Views
    No one has replied