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. Registering C++ objects in QML
Forum Updated to NodeBB v4.3 + New Features

Registering C++ objects in QML

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 7 Posters 2.7k 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.
  • J J.Hilk
    20 Sept 2019, 05:47

    Wow this escalated quickly!

    I think the fork is a good idea, tbh.

    @kshegunov said in Registering C++ objects in QML:

    I continue to claim that a "singleton" is nothing more than a glorified global variable, so it should be treated exactly as such - a bad monstrously stupid idea in 99.999% of cases!

    sadly, in combination with QML your options are limited. If you want to access the class from cpp and QML you can do one of the following

    • Singleton, instance in cpp and exactly where you need it in qml
    • Normal instance in cpp, a global property accessible in all qml files
    • using find child to search for your qml item and do the connect in cpp. This falls apart as soon as you start to dynamically load your qml files

    So, Pest Cholera, or Malaria.

    @stehlo said in Registering C++ objects in QML:

    Without going into extra detail which would detract from the main point, the attempt to deleteLater the QObject unnaturally at the point of the application being aboutToQuit causes either of the two following fatal errors, depending on whether we do this for the networking singleton or the database one:

    QObject: shared QObject was deleted directly. The program is malformed and may crash.
    abort_message: assertion "Pure virtual function called!" failed
    Fatal signal 6 (SIGABRT), Aborted

    or

    null pointer dereference
    Fatal signal 11 (SIGSEGV), Segmentation fault

    The attempt to deleteLater is happening either too early or two late.

    I actually have to disagree.
    after reading the post by @Chris-Kawa I changed my own project to include the about to quit cleanup. That's for about 10 Singletons not once did I have one of your errors mentions above.

    I would say there's still something going on that causes your issue, but I think it's user -rather than framework related

    K Offline
    K Offline
    kshegunov
    Moderators
    wrote on 20 Sept 2019, 08:11 last edited by kshegunov
    #21

    @j-hilk said in Registering C++ objects in QML:

    Normal instance in cpp, a global property accessible in all qml files

    What I wrote. Normal object in C++, a context property in QML. Which is kind of the point of having context properties to begin with, is it not?

    Read and abide by the Qt Code of Conduct

    J 1 Reply Last reply 20 Sept 2019, 08:17
    0
    • K kshegunov
      20 Sept 2019, 08:11

      @j-hilk said in Registering C++ objects in QML:

      Normal instance in cpp, a global property accessible in all qml files

      What I wrote. Normal object in C++, a context property in QML. Which is kind of the point of having context properties to begin with, is it not?

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 20 Sept 2019, 08:17 last edited by
      #22

      @kshegunov yes, and also the reason why I think the Singleton is the lesser of 2 evils, as it's not globally accessible in all Files but has to be explicitly imported inside the File.

      Wouldn't you agree 😉


      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.

      1 Reply Last reply
      0

      21/22

      20 Sept 2019, 08:11

      • Login

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