Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QML Application Crashes on window->show
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QML Application Crashes on window->show

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.4k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    rizoritis
    wrote on last edited by
    #1

    Hello,

    I made a very basic application where I am just creating a rectangle in QML and showing it from my main as follows:

    main.cpp
    @#include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QQuickWindow>

    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QStringLiteral("C:/Qt/Tools/QtCreator/bin/FreakingWork/main.qml"));
    
    QObject *topLevel = engine.rootObjects().value(0);
    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    window->show();
    
    return app.exec&#40;&#41;;
    

    }@

    main.qml
    @import QtQuick 2.0

    Rectangle {
    width: 100
    height: 62
    }@

    For some reason when I run the above it says that "The program unexpectedly finished" and that the .exe has crashed. It seems that what I am doing is very basic so I do not see what can cause it to crash.

    If I comment out the window->show portion it does not crash until I tell the program to stop running. Any ideas?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Two possibilities:

      topLevel is NULL

      topLevel is not a QQuickWindow thus window is NULL

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rizoritis
        wrote on last edited by
        #3

        [quote author="SGaist" date="1393534511"]Hi,

        Two possibilities:

        topLevel is NULL

        topLevel is not a QQuickWindow thus window is NULL[/quote]

        Thanks for the quick response. In the back of my mind I knew that was the problem. I guess the better question is why is that happening. I have used this same code numerous times without error, but for some reason now I am having a problem. I checked my path to main.qml and it is fine. I am not sure how else to debug it.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rizoritis
          wrote on last edited by
          #4

          I solved the problem. It was that in my main.qml, my top level component was a rectangle. I changed it to ApplicationWindow so that I actually had a window and it worked. I had to add import QtQuick.Controls 1.0 as well.

          Thanks for the help SGaist!

          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