Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. singleton

    Log in to post
    • All categories
    • K

      Unsolved When to register c++ singleton types in QML module plugins?
      QML and Qt Quick • qml module plugin singleton c++ • • Knutid

      1
      0
      Votes
      1
      Posts
      171
      Views

      No one has replied

    • S

      Solved Is it possible to receive a signal from a class that was instantiated twice?
      General and Desktop • signals & slots singleton • • SpaceToon

      10
      0
      Votes
      10
      Posts
      291
      Views

      S

      @SpaceToon said in Is it possible to receive a signal from a class that was instantiated twice?:

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      MainWindowA m;
      m.show();
      return a.exec();
      }

      Where is your MainWindowB instance create? Does MainWindowA do this somewhere?

      In general, I would expect something along these lines in main:

      int main(int argc, char *argv[]) { QApplication a(argc, argv); emitSignalClass emitter; MainWindowA mA(&emitter); mA.show(); MainWindowB mB(&emitter); mB.hide(); return a.exec(); }

      Create an instance of your signal-emitting class first and hand it to the constructurs. Store a pointer to the same emitter object as member variable in both MainWindowA and MainWindowB.

    • G

      Unsolved Make a module available to other apps
      QML and Qt Quick • qml singleton styling • • GrahamLa

      7
      0
      Votes
      7
      Posts
      721
      Views

      G

      @LeLev
      Ok - looks like I need to follow that up

    • A

      Unsolved Singletons for small UIs (QML based). To use or not to use?
      General and Desktop • singleton • • Ankit.Jain

      4
      0
      Votes
      4
      Posts
      381
      Views

      A

      @jsulm They are created inside main.cpp. Usage is high as pretty much every calculation is done in 'em.

      @J-Hilk They are currently registered via setContextProperty and can hence be used freely throughout our QML code but not the Qt/C++ part.

    • J

      Solved Singleton pattern with MinGW
      General and Desktop • mingw64 singleton • • Jendker

      5
      0
      Votes
      5
      Posts
      670
      Views

      J

      @SGaist Thank you, but this is actually the class where I am creating the tables when database is empty and holding all the models and necessary functions to work on them. So it is fine in this case :)

    • b2soft

      Unsolved C++ Singleton import inside Qt Creator's QML Designer
      QML and Qt Quick • qt creator qml singleton import designer • • b2soft

      2
      0
      Votes
      2
      Posts
      553
      Views

      J

      I know this answer is a bit late, but one solution that comes to my mind is to separate UI from logic. Create one file (e.g. a ui.qml file) for your UI and use it in another qml file.

    • L

      Unsolved CPP QML Singleton registered with qmlRegisterSingletonType fails to load
      QML and Qt Quick • qml singleton cpp lib • • Lolleko

      1
      0
      Votes
      1
      Posts
      1146
      Views

      No one has replied

    • eggbertx

      Solved Trying to create a singleton and getting LNK2019 error
      General and Desktop • singleton c++ • • eggbertx

      18
      0
      Votes
      18
      Posts
      6043
      Views

      kshegunov

      @eggbertx said in Trying to create a singleton and getting LNK2019 error:

      Sorry, I meant the second code block, not the first. I'm not very familiar with assertions in general, so I've never heard of Q_ASSERT.

      The assertion here is only a tool to detect creating more than one instance of the class. Q_ASSERT is a Qt macro for regular debug assertions, it will be removed in release mode, so its purpose (as assertions in general) is to catch programmer errors while debugging. So if you use the class above like this:

      Singleton object1; Singleton object2; //< Here the assertion will be tripped and you can catch the error while debugging

      Adding the code in the second block fixed the issue.

      Do you mean the main window constructor where the connect is made? All code blocks are part of one single example, so I'd expect them to work together only. :)

    • N

      Unsolved How to load a QML view from a singleton C++ class within a main window engine
      QML and Qt Quick • qml c++ interface loader singleton • • notalocal

      3
      0
      Votes
      3
      Posts
      1684
      Views

      N

      I appreciate your response, it lead me to a lot of research on the topic! I figured out it was much easier to implement a tabview on the main view and then to connect the signals with the child objects which were themselves individual views.

    • Stefan Monov76

      Unsolved Qt: I defined and registered a QML singleton in C++. How do I access this singleton from C++?
      QML and Qt Quick • singleton c++ • • Stefan Monov76

      3
      0
      Votes
      3
      Posts
      2581
      Views

      S

      @Stefan-Monov76 you could also use something like that:

      class FileIO: public QObject{ Q_OBJECT public: //singleton type provider function for Qt Quick static QObject* fileIOSingletonTypeProvider(QQmlEngine *engine, QJSEngine *scriptEngine); //singleton object provider for C++ static FileIO* instance(); void myFancyFunction(); }; QObject* FileIO::fileIOSingletonTypeProvider(QQmlEngine *engine, QJSEngine *scriptEngine){ Q_UNUSED(engine) Q_UNUSED(scriptEngine) return FileIO::instance(); } FileIO* FileIO::instance() { static FileIO* fileIO = new FileIO(); return fileIO; } void FileIO::myFancyFunction(){ //do something }

      In that case you could get the singleton, with:

      FileIO::instance()->myFancyFunction();
    • bnmalfrax

      Solved Unable to handle unregistered datatype
      QML and Qt Quick • qml handles error type singleton • • bnmalfrax

      5
      0
      Votes
      5
      Posts
      7368
      Views

      bnmalfrax

      Thanks, it work !