Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. SetMainQmlFile it doesn't work
QtWS25 Last Chance

SetMainQmlFile it doesn't work

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • freddy311082F Offline
    freddy311082F Offline
    freddy311082
    wrote on last edited by
    #1

    Hi guys....

    I have this qrc file:
    @
    <RCC>
    <qresource prefix="/">
    <file>qml/pilarApp/main.qml</file>
    </qresource>
    </RCC>
    @

    and in my main.cpp I have:

    @
    QGuiApplication app(argc, argv);
    QtQuick2ApplicationViewer viewer;
    viewer.rootContext()->setContextProperty("PilarApp", new System);
    viewer.setMainQmlFile(QStringLiteral("qrc:/qml/pilarApp/main.qml"));
    viewer.showExpanded();
    return app.exec();@

    but it doesn't work

    I had try with:
    @
    "qrc:/qml/pilarApp/main.qml"
    "qrc://qml/pilarApp/main.qml"
    ":/qml/pilarApp/main.qml"
    "://qml/pilarApp/main.qml"
    @

    and the error which wtcreator give me is like this:

    @
    file:///home/freddy/Trabajo/eulerideas/Salon Pilar App/qt-creator/build-pilarApp-Clang-Debug/qrc:/qml/pilarApp/main.qml: File not found
    @

    in my .pro file I have defined
    @
    RESOURCES +=
    resource.qrc
    @

    so.... what i'm doing wrong ???

    best regards to everyone

    freddy

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Try
      @
      viewer.setSource(QUrl("qrc:/qml/pilarApp/main.qml"));
      @
      instead of
      @
      viewer.setMainQmlFile(QStringLiteral("qrc:/qml/pilarApp/main.qml"));
      @

      157

      1 Reply Last reply
      1
      • freddy311082F Offline
        freddy311082F Offline
        freddy311082
        wrote on last edited by
        #3

        Hi p3c0.... Thanks for answer....

        your solution solve my problem, but.... what happend if the I use QtQuick2ControlsApplicationViewer class instead QtQuick2ApplicationViewer class ???

        this class don't have setSource method because this class, which is generated by the QtCreator project, doesn't inherit from QQuickView

        regards

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Hi freddy311082,

          See my 2nd post at http://qt-project.org/forums/viewthread/37597 . Qt Creator forgot to generate the relevant code, but you can add it yourself. (This issue is fixed for Qt Creator 3.1, which will be released with Qt 5.3)

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • freddy311082F Offline
            freddy311082F Offline
            freddy311082
            wrote on last edited by
            #5

            Hi JKSH

            I had read your post, but I don't have clear something...

            if i have this code into my main function:

            @
            Application app(argc, argv);
            QtQuick2ControlsApplicationViewer viewer;
            QQmlEngine *engine = viewer.engine();
            QQmlContext *context = engine->rootContext();
            context->setContextProperty("systemControler", new System);
            viewer.setMainQmlFile(QStringLiteral("/qml/adviser/main.qml"));
            viewer.show();
            return app.exec();
            @

            how can I change the line where I'm calling setMainQmlFile ?? your post make porpose add a new definition to the QtQuick2ControlsApplicationViewer class, but let be clear how fix this problem...

            regards my friend

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              Hi freddy311082,

              I don't see anything wrong with your code and you shouldn't need to change that line. What issue are you facing?

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • freddy311082F Offline
                freddy311082F Offline
                freddy311082
                wrote on last edited by
                #7

                Hi JKSH

                I need change the following line

                @
                viewer.setMainQmlFile(QStringLiteral("/qml/adviser/main.qml"));
                @

                by someone like this

                @
                viewer.setMainQmlFile(QStringLiteral("qrc:/qml/adviser/main.qml"));
                @

                but the last one it odesn't work

                who can I do that using QtQuick2ControlsApplicationViewer class ?? that is my question

                regards

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  Hi freddy311082,

                  It looks like other people are struggling with this issue too: https://bugreports.qt-project.org/browse/QTCREATORBUG-11277 It will be fixed for Qt Creator 3.1.

                  In the meantime, you can edit the generated code. Open qtquick2controlsapplicationviewer.cpp and change this line:
                  @
                  void QtQuick2ControlsApplicationViewer::setMainQmlFile(const QString &file)
                  {
                  ...
                  // component.loadUrl(QUrl::fromLocalFile(d->mainQmlFile));
                  component.loadUrl(QUrl(file));
                  ...
                  }
                  @

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved