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. Application crashing on closing the window Application
Forum Updated to NodeBB v4.3 + New Features

Application crashing on closing the window Application

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 741 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.
  • A Offline
    A Offline
    Anita
    wrote on last edited by
    #1

    Hi,

    I have a QT C++ singleton class, in which we have a QMLProperty and invokable function, hence registered this class as qmlRegisterSingletonType in main.cpp and using the class object in my qml.
    On closing the application, the application crashes.
    the singleton class return the address of a static object of the class.
    getInstance function:
    static myclass myclassObj;
    return &myclassObj;

    Is the above code wrong ? because if i don't use the class object in qml, qt exits neatly with code exited with 0.

    Using Qt MSVC compiler to compile and run the application.

    @JKSH @dheerendra @J-Hilk

    J.HilkJ 1 Reply Last reply
    0
    • A Anita

      Hi,

      I have a QT C++ singleton class, in which we have a QMLProperty and invokable function, hence registered this class as qmlRegisterSingletonType in main.cpp and using the class object in my qml.
      On closing the application, the application crashes.
      the singleton class return the address of a static object of the class.
      getInstance function:
      static myclass myclassObj;
      return &myclassObj;

      Is the above code wrong ? because if i don't use the class object in qml, qt exits neatly with code exited with 0.

      Using Qt MSVC compiler to compile and run the application.

      @JKSH @dheerendra @J-Hilk

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Anita can you show us the getter functions and the destructor.

      Who is supposed to manage the lifetime of the singleton, QML or c++?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      A 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @Anita can you show us the getter functions and the destructor.

        Who is supposed to manage the lifetime of the singleton, QML or c++?

        A Offline
        A Offline
        Anita
        wrote on last edited by
        #3

        @J-Hilk

        Hi,

        The destructor is empty.

        using a Q_INVOKABLE fn :
        Q_INVOKABLE bool getvalue(){ return true;}

        in main.cpp :
        registered the object using:
        qmlRegisterSingletonType<testinginstance>("Test", 1, 0, "Test",getInstance);

        in main.qml:
        import Test 1.0
        property bool value : Test.getvalue()

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          if you can post your sample completely, it will help us to help you

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          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