Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Signals and slots C++ too QML



  • Up until now I haven't had to mess around with the C++ code on the back-end of this GUI. I have been able to avoid altering C++ code but I can't any longer. So I need to learn how it works. What I am trying to do is create a function that emit's a signal whenever it is called and I would like to call it from QML by establishing a connection, something like this:

    Connections
          {
            target: presentationManager.guiSettingsPresenter
            onWizardBoolHasChanged{//do some logic here}
          }
    

    I also need to be able to call the method from QMl, something like this:

    presentationManager.guiSettingsPresenter.wizardBool
    

    here is the function I have created to call:

    void GuiSettingsPresenter::wizardBool()
    {
        m_wizardBool == false ? m_wizardBool = true : m_wizardBool = false;
        emit wizardBoolHasChanged();
    }
    

    it's rather simple it just emit's a signal whenever the bool is flipped. Here it is instantiated in the header and I made a signal for it:

    public:
        void wizardBool();
    
    signals:
        void wizardBoolHasChanged();
    
    private:
        bool m_wizardBool = false;
    

    I believe I have done everything right so far but perhaps not. I think the next thing I need is a Q_PROPERTY? Do I even need a Q_PROPERTY I tried testing it and it doesn't seem to work.



  • Never mind I figured this out I guess I needed to import the manager inside of main... closing.


Log in to reply