Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.0k Topics 77.4k Posts
  • Deployment and development issues of programs using Qt Quick plug-ins

    Unsolved
    2
    0 Votes
    2 Posts
    162 Views
    F
    Create a makefile using .pro for ex: qmake sample.pro .You will get a MakeFile.Then run make and make install -> this command will install the plug-in in the corresponding director with correct inputs in .pro file.
  • Compiler error for absent qmlcachegen

    Unsolved
    3
    0 Votes
    3 Posts
    2k Views
    P
    another alternative is so create a custom recipe nativesdk-packagegroup-qt5-toolchain-host.bbappend and put this line RDEPENDS_${PN} += " nativesdk-qtdeclarative-tools" and rebuild the sdk best regards Enrico
  • 0 Votes
    1 Posts
    424 Views
    No one has replied
  • C++-to-QML error handling

    Unsolved
    1
    0 Votes
    1 Posts
    338 Views
    No one has replied
  • Threads in qt qml application

    Unsolved
    3
    0 Votes
    3 Posts
    506 Views
    M
    All qt applications create multiple threads.
  • Qt Quick 3D use transparent textures with Model

    Unsolved
    1
    0 Votes
    1 Posts
    303 Views
    No one has replied
  • workerscript always recieve the first version of ListModel

    Unsolved
    1
    0 Votes
    1 Posts
    121 Views
    No one has replied
  • Make stringlistmodel example workl with ListView not being the top level item

    Solved
    2
    0 Votes
    2 Posts
    192 Views
    H
    I managed to find out myself. Here is the code, in case others might want the same: C++ #include <QGuiApplication> #include <QQmlApplicationEngine> #include <QStringList> #include <qqmlengine.h> #include <qqmlcontext.h> #include <qqml.h> #include <QtQuick/qquickitem.h> #include <QtQuick/qquickview.h> int main(int argc, char ** argv) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/view.qml")); QObject::connect( &engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) {if (!obj && url == objUrl) QCoreApplication::exit(-1);}, Qt::QueuedConnection); engine.load(url); // get the root object of the loaded QML QList<QObject*> root_objects(engine.rootObjects()); QStringList projectList = { "Project 1", "Project 2", "Project 3", "Project 4" }; const QObjectList& children(root_objects[0]->children()); if (!children.isEmpty()) { QList<QObject*> lists(root_objects[0]->findChildren<QObject*>("listViewProjects")); if (!lists.isEmpty()) lists.first()->setProperty("model", QVariant::fromValue(projectList)); } return app.exec(); } QML import QtQuick 2.4 import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Window 2.5 Window { id: window visible: true width: 640 height: 480 title: qsTr("ListView") ListView { id: listViewProjects objectName: "listViewProjects" anchors.fill: parent delegate: Item { id: project required property string modelData required property int index height: 30 width: parent.width Text { anchors.verticalCenter: parent.verticalCenter text: parent.modelData } MouseArea { anchors.fill: parent onClicked: listViewProjects.currentIndex = parent.index } } highlight: Rectangle { color: "lightsteelblue"; radius: 2 } focus: true } } It also shows how to use the index variable for setting the selection with the mouse: once a required property is declared (modelData), you must declare all properties you intend to use. This is not shown in any other example I could find. If you fail to do this, index is undefined.
  • Pop up Menu outside QtWindow

    Unsolved
    1
    0 Votes
    1 Posts
    174 Views
    No one has replied
  • Different views QtCreator vs runtime

    Unsolved
    1
    0 Votes
    1 Posts
    179 Views
    No one has replied
  • QML and SFML

    Unsolved
    1
    0 Votes
    1 Posts
    422 Views
    No one has replied
  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    2 Posts
    350 Views
    JonBJ
    @kayshika export QT_DEBUG_PLUGINS=1 and then run your app for diagnostic information. Probably need to apt-get some other library.
  • How do I move my map markers in realtime?

    Unsolved
    1
    0 Votes
    1 Posts
    399 Views
    No one has replied
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    4 Views
    No one has replied
  • ListView - how to highlight current item

    Solved
    4
    0 Votes
    4 Posts
    3k Views
    P
    https://github.com/pawlosck/QMLClock/blob/aaf6c65e5c1cd775c65a510f72d11de339da3709/alarm_list_window.qml The most important things: Item change color if is selected or not. Selected Item is black and other is red color: ListView.isCurrentItem ? "black" : "red" Add MouseArea with onClicked into ListView to change current Item using mouse. MouseArea { anchors.fill: parent onClicked: setCurrentItem(mouseX, mouseY) } Full code of ListView ListView { spacing: 5 clip: true id: listviewID anchors.fill: parent width: parent.width height: parent.height/2 model: modelID delegate: delegatID MouseArea { anchors.fill: parent onClicked: setCurrentItem(mouseX, mouseY) } } Full code of delegate with Items Component { id: delegatID Rectangle { id: alarmItemDelegate width: listviewID.width height: 50 border.width: 1 radius: 5 color: ListView.isCurrentItem ? "grey" : "transparent" Item { anchors.fill: parent Text { id: remainingAl x: 5 anchors.top: parent.top text: "Remaining: " + model.remainingTime color: alarmItemDelegate.ListView.isCurrentItem ? "yellow" : "black" } Text { id: typeAl x: 5 anchors.verticalCenter: parent.verticalCenter text: "Type: " + model.typeAlarm color: alarmItemDelegate.ListView.isCurrentItem ? "yellow" : "black" } Text { id: messageAl x: 5 anchors.bottom: parent.bottom text: "message: " + model.messageAlarm color: alarmItemDelegate.ListView.isCurrentItem ? "yellow" : "black" } } } }
  • TextInput - how to restrict width of text to parent's width

    Solved
    6
    0 Votes
    6 Posts
    950 Views
    P
    Problem solved. I had to add option clip=true into TextInput. After that, text is not expanded beyond border of Rectangle. https://github.com/pawlosck/QMLClock/commits/0c2e21ddd26dd9b59130f858b399b7fd8de662d8 Rectangle { id: typeInfoBorder border.width: 1 // color: "green" Layout.fillWidth: true Layout.minimumWidth: 40 height: 20 TextInput { id: typeInfoLabel width: parent.width height: parent.height clip: true text: typeInfoString onTextChanged: { var index = 0 for (var alarm of list_of_alarms) { if (alarm.getTimerID() === listviewID.currentItem.getTimerID()) { alarm.setTypeOfAlarm(text) } } } } }
  • How to save current index of ComboBox for supported map types

    Solved
    3
    0 Votes
    3 Posts
    431 Views
    edipE
    Thank you @LeLev I found a solution before but your solution is much better.
  • 0 Votes
    2 Posts
    1k Views
    T
    I've developed a hackish workaround - if you're frustrated by this issue too, this "fix" is ugly but might help in the short-term: I noticed that Qt Creator still recognizes the old qmlRegisterType function calls if they're invoked from main in a project. So naturally, I made a custom compiler step for qmake that generates a header file with all QML_ELEMENT-tagged classes registered in a function. First, make sure you've set up qmltypes in your project as usual - your QML_IMPORT_NAME and all that is set. Add to the bottom of MyProject.pro: type_registrar_unfucker.name = type_registrar_unfucker type_registrar_unfucker.input = TYPE_REGISTRAR_SOURCES type_registrar_unfucker.commands = python3 $$PWD/type_unfuck.py ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} $$QML_IMPORT_NAME $$QML_IMPORT_MAJOR_VERSION type_registrar_unfucker.output = ${QMAKE_FILE_IN_BASE}.h type_registrar_unfucker.clean = ${QMAKE_FILE_IN_BASE}.h type_registrar_unfucker.variable_out = HEADERS QMAKE_EXTRA_COMPILERS += type_registrar_unfucker TYPE_REGISTRAR_SOURCES += $$OUT_PWD/myproject_metatypes.json Add as type_unfuck.py in your source directory: # type unfuck # ----------- # This python script deals with the issue of Qt Creator not being able to recognize element types # registered using 'QML_ELEMENT'. # # It does so by generating a header, 'myprojectname_metatypes.h'. # Include this header ONLY in main.cpp, and then call `registerTypes()` first thing in `main`. # Then, Qt Creator will stop whining. import sys import json source_path = sys.argv[1] dest_path = sys.argv[2] import_name = sys.argv[3] import_major = sys.argv[4] with open(source_path) as f: data = json.load(f) includes = ["QtQml"] types = [] for file in data: includes.append(file["inputFile"]) for type in file["classes"]: if "classInfos" in type and {"name":"QML.Element","value":"auto"} in type["classInfos"]: types.append(type["className"]) with open(dest_path, 'w') as f: for i in includes: f.write(f'#include <{i}>\n') f.write('void registerTypes() {\n') for t in types: f.write(f'\tqmlRegisterType<{t}>("{import_name}", {import_major}, 0, "{t}");\n') f.write('}\n') Then, just add #include <myproject_metatypes.h> to your project's main.cpp and invoke registerTypes(); immediately in your main function. Build your project, then click on Tools -> QML/JS -> Reset Code Model, and Qt Creator should now recognize your custom components correctly.
  • delete Item and load another on the same ApplicationWindow

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