<div dir="ltr"><div>I copied the qml loading code from another working example, I was just testing a change in the QML content.</div><div><br></div><div>I'd have to dig further about the lambda</div><div><br></div>MenuBar.pro<div>===========<br>QT += quick<br><br>CONFIG += c++11<br><br># The following define makes your compiler emit warnings if you use<br># any Qt feature that has been marked deprecated (the exact warnings<br># depend on your compiler). Refer to the documentation for the<br># deprecated API to know how to port your code away from it.<br>DEFINES += QT_DEPRECATED_WARNINGS<br><br># You can also make your code fail to compile if it uses deprecated APIs.<br># In order to do so, uncomment the following line.<br># You can also select to disable deprecated APIs only up to a certain version of Qt.<br>#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0<br><br>SOURCES += \<br>        main.cpp<br><br>RESOURCES += main.qrc<br><br># Additional import path used to resolve QML modules in Qt Creator's code model<br>QML_IMPORT_PATH =<br><br># Additional import path used to resolve QML modules just for Qt Quick Designer<br>QML_DESIGNER_IMPORT_PATH =<br><br># Default rules for deployment.<br>qnx: target.path = /tmp/$${TARGET}/bin<br>else: unix:!android: target.path = /opt/$${TARGET}/bin<br>!isEmpty(target.path): INSTALLS += target<br><br>main.qrc</div><div>=======  <br><RCC><br>    <qresource prefix="/"><br>        <file>MenuBar.qml</file><br>    </qresource><br></RCC><br><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 2 Jun 2021 at 20:36, Tony Rietwyk <<a href="mailto:tony@rightsoft.com.au">tony@rightsoft.com.au</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>Hi Nicholas, <br>
    </p>
    <p>The short answer is because your C++ is doing completely
      different things to the python code.  :O)<br>
    </p>
    <p>I'm not sure about using QML.  Have you included the qml file as
      a resource correctly to access via qrc:?  You aren't checking the
      result of the engine.load.  Also, why is the lambda exiting the
      application when the objectCreated matches the url? <br>
    </p>
    <p>Have run the Qt QML examples?  How is your C++ code different to
      those? <br>
    </p>
    <p>Hope that helps, Tony</p>
    <p><br>
    </p>
    <div>On 3/06/2021 11:33 am, Nicholas Yue
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">Hi,
        <div><br>
        </div>
        <div>  I am learning about QML.</div>
        <div><br>
        </div>
        <div>  I would like to find out why the PySide2 loading of the
          QML file results in a visible window but the C++ one does not.
          The compiled application runs but no window is displayed.<br>
          <br>
          MenuBar.qml<br>
          ===========<br>
          import QtQuick 2.4<br>
          import QtQuick.Controls 2.13<br>
          <br>
          ApplicationWindow {<br>
              visible: true<br>
              width: 720<br>
              height: 480<br>
              title: "simple window"<br>
          <br>
              menuBar: MenuBar{<br>
                  Menu{<br>
                      title: "Menu1"<br>
                  }<br>
          <br>
                  Menu{<br>
                      title: "Menu2"<br>
                  }<br>
          <br>
                  Menu{<br>
                      title: "&Menu3"<br>
                  }<br>
              }<br>
          }<br>
          <br>
          main.cpp<br>
          ========<br>
          #include <QGuiApplication><br>
          #include <QQmlApplicationEngine><br>
          <br>
          int main(int argc, char *argv[])<br>
          {<br>
             
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);<br>
          <br>
              QGuiApplication app(argc, argv);<br>
          <br>
              QQmlApplicationEngine engine;<br>
              const QUrl url(QStringLiteral("qrc:/MenuBar.qml"));<br>
              QObject::connect(&engine,
          &QQmlApplicationEngine::objectCreated,<br>
                               &app, [url](QObject *obj, const QUrl
          &objUrl) {<br>
                  if (!obj && url == objUrl)<br>
                      QCoreApplication::exit(-1);<br>
              }, Qt::QueuedConnection);<br>
              engine.load(url);<br>
          <br>
              return app.exec();<br>
          }<br>
          <br>
          main.py<br>
          =======<br>
          import sys<br>
          from PySide2 import QtCore, QtGui, QtQml<br>
          <br>
          if __name__ == '__main__':<br>
          <br>
             
          QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)<br>
              app = QtGui.QGuiApplication(sys.argv)<br>
          <br>
              engine = QtQml.QQmlApplicationEngine()<br>
          <br>
              url = QtCore.QUrl.fromLocalFile('MenuBar.qml')<br>
              engine.load(url)<br>
              if not engine.rootObjects():<br>
                  sys.exit(-1)<br>
          <br>
              sys.exit(app.exec_())<br>
          <div><br>
          </div>
          -- <br>
          <div dir="ltr">
            <div dir="ltr">Nicholas Yue<br>
              Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5<br>
              Custom Dev - C++ porting, OSX, Linux, Windows<br>
              <a href="http://au.linkedin.com/in/nicholasyue" target="_blank">http://au.linkedin.com/in/nicholasyue</a><br>
              <a href="https://vimeo.com/channels/naiadtools" target="_blank">https://vimeo.com/channels/naiadtools</a><br>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset></fieldset>
      <pre>_______________________________________________
Interest mailing list
<a href="mailto:Interest@qt-project.org" target="_blank">Interest@qt-project.org</a>
<a href="https://lists.qt-project.org/listinfo/interest" target="_blank">https://lists.qt-project.org/listinfo/interest</a>
</pre>
    </blockquote>
  </div>

_______________________________________________<br>
Interest mailing list<br>
<a href="mailto:Interest@qt-project.org" target="_blank">Interest@qt-project.org</a><br>
<a href="https://lists.qt-project.org/listinfo/interest" rel="noreferrer" target="_blank">https://lists.qt-project.org/listinfo/interest</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Nicholas Yue<br>Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5<br>Custom Dev - C++ porting, OSX, Linux, Windows<br><a href="http://au.linkedin.com/in/nicholasyue" target="_blank">http://au.linkedin.com/in/nicholasyue</a><br><a href="https://vimeo.com/channels/naiadtools" target="_blank">https://vimeo.com/channels/naiadtools</a><br></div></div>