Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
19.9k Topics 76.8k Posts
  • Custom C++ QML element with arguments

    Unsolved
    7
    0 Votes
    7 Posts
    817 Views
    A

    This has been a question of mine for over a year. I resorted to having a factory class that has methods to instantiate various view models (and pass in dependencies) and return the pointer to that view model. This factory would be exposed to QML via singleton or contextProperty at the start of my program. Any QML view can decide which view models it wants and doesn't deal with dependency injection.

    Here is an example:

    class ViewModelFactory : public QObject { Q_OBJECT QML_ELEMENT QML_SINGLETON public: Q_INVOKABLE HomeViewModel* createHomeViewModel(QObject* parent = nullptr) { // Inject dependencies from ApplicationModels auto& appModels = ApplicationModels::instance(); return new HomeViewModel(appModels.smartHomeService(), appModels.userService(), parent); } };

    Now, the above example makes ApplicationModels a singleton and passes it to the view model, but you could imagine a world where the factory can manage the dependencies without them being singletons.

    It took a lot of thinking and I gathered this approach by looking at how QtWidgets does things: a very hierarchical object structure where the MainWindow class would contain everything within it and proctor instantiation, DI, and more.

    QML just has access to what is publicly exposed by the ApplicationModel/factory, and no longer needs access to dependencies for ViewModels to use their desired view model.

    Note: I have not tested this yet (my fear being that I do NOT know the impact of calling factory methods on init of a Qml component)

  • OpenSSL with QML Image source. Self signed ca-certificate

    Solved
    8
    1 Votes
    8 Posts
    1k Views
    A

    The error you're encountering ("QML Image: SSL handshake failed") typically happens when there's a problem establishing a secure connection between the QML application and the server you're trying to connect to. This is often caused by issues with SSL certificates, the server's configuration, or network problems. To resolve this error, you can try the following steps:

    Check SSL/TLS Configuration: Ensure that the server you're connecting to has a valid SSL certificate. If you're using a self-signed certificate, it may not be trusted by the system. Make sure the certificate is correctly installed.

    Update QML/Qt and SSL Libraries: Sometimes, outdated libraries can cause compatibility issues. Make sure you're using the latest version of QML, Qt, and SSL libraries (OpenSSL).

    Verify Network and Proxy Settings: If you're behind a proxy or firewall, ensure the settings are properly configured and not blocking the SSL handshake.

    Trust Certificates: If the certificate isn't recognized by the system, you may need to manually add the certificate to the trust store.

    Enable Debugging: You can enable debugging in Qt to get more information about the SSL handshake failure. Set the following environment variable before running your application:

    ini
    Copy
    Edit
    QT_DEBUG_PLUGINS=1
    For more detailed information and troubleshooting, you can refer to the following resources:

    Qt SSL documentation
    OpenSSL documentation
    Common SSL handshake errors
    Let me know if you need more help!

  • Sync QQuickPaintedItem and QML painting

    Solved
    3
    0 Votes
    3 Posts
    113 Views
    -

    Ah, didn't read this. Thanks for the hint...

  • QML SelectionRectangle behavior change

    Unsolved
    1
    0 Votes
    1 Posts
    78 Views
    No one has replied
  • Correct way to deploy QML plugin with support of QDS

    Unsolved
    1
    0 Votes
    1 Posts
    87 Views
    No one has replied
  • STM32MP157C QT Quick portrait orientation

    Unsolved
    1
    0 Votes
    1 Posts
    72 Views
    No one has replied
  • 0 Votes
    3 Posts
    154 Views
    P

    Snipaste_2025-02-21_19-04-28.jpg
    The complete picture looks like this

  • Bug in qt 5.15.2: Button.checkable = false is gettin ignored

    Unsolved
    2
    0 Votes
    2 Posts
    111 Views
    MarkkyboyM

    Checkable and checked are not components of Button QML.

    A similar question here; https://forum.qt.io/topic/36479/solved-button-checkable-and-checked-not-working albeit a different answer/outcome from my response. Regardless, I still myself, cannot use checkable or checked with Button.

  • 0 Votes
    3 Posts
    116 Views
    S

    @SGaist Thank you so much!

  • 0 Votes
    2 Posts
    115 Views
    M

    It turns out wrapping the child Layout in an Item does the trick. Don't know why and whether this is the best solution

    import QtQuick import QtQuick.Controls import QtQuick.Layouts Window { height: 300 width: 240 visible: true StackLayout { anchors.fill: parent Item { Layout.fillWidth: true Layout.fillHeight: true ColumnLayout { anchors.fill: parent Rectangle { color: "red" Layout.preferredWidth: 100 Layout.preferredHeight: 50 Layout.alignment: Qt.AlignHCenter // Center within ColumnLayout } // other items } } // other items } }
  • 0 Votes
    6 Posts
    200 Views
    jsulmJ

    @VITORdk said in Error: ":\Qt\6.7.3\android_arm64_v8a\include\QtCore\qnamespace.:24:1: error: error: Parse error at "__attribute__"":

    So I reduced my file to an empty file

    You can't compile an empty file. Also, I guess your project consists of more than just an empty file.
    Please provide more information, else nobody knows what you're doing and what the problem is.
    Did you try to create a new widget project in QtCreator and build it for Android?

  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    2 Views
    No one has replied
  • 0 Votes
    1 Posts
    66 Views
    No one has replied
  • MapPolygon border color doesnt change on update

    Unsolved
    1
    0 Votes
    1 Posts
    42 Views
    No one has replied
  • No word suggestions on Android in TextEdit

    Solved
    6
    1 Votes
    6 Posts
    267 Views
    M

    Fixed in 6.8.2

  • QML + CSS

    17
    0 Votes
    17 Posts
    27k Views
    B

    I wonder if that forum post is referring to text components that support html to some extent, rather than to QML itself?

  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    2 Views
    No one has replied
  • 0 Votes
    7 Posts
    215 Views
    B

    Though that page doesn't show any QML examples as far as I can see.

    I recall having to try a few things when I first wanted to do this a few years ago. I don't know if what I arrived at is the "correct" approach, but the format that I found to work in QML and have stuck to ever since involves using a triple forward slash like this:

    source: "qrc:///images/my-image.png"
  • Facing an issue with Listview in Repeater

    Unsolved
    2
    0 Votes
    2 Posts
    82 Views
    jeremy_kJ

    @Praveen-Illa said in Facing an issue with Listview in Repeater:

    Hi Team,

    I am trying to control the visibility of the listview control on every button click for respective data model.
    But, I am getting below errors at "visible: buttonRepeater.model.expanded"
    Unable to assign [undefined] to bool

    Edited to emphasize the problem:

    Repeater { id: buttonRepeater model: groupModel delegate: Column { ListView { visible: buttonRepeater.model.expanded } } }

    buttonRepeater.model.expanded is attempting to access a property called expanded in buttonRepeater's model, not a role called expanded within a row of the model. Printing the values of buttonRepeater and buttonRepeater.model should make this clear.

  • Qt Quick with CMake Error

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