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. Signal from c++ for messagedialog on Qml

Signal from c++ for messagedialog on Qml

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 810 Views
  • 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.
  • Nio74N Offline
    Nio74N Offline
    Nio74
    wrote on last edited by
    #1

    I have mi signal in to c++

    Backend::Backend(QObject *parent) : QObject(parent)
    
    
    {
        //m_sSettingsFile = QApplication::applicationDirPath().left(1) + ":/demosettings.ini";
        //QSettings settings(m_sSettingsFile, QSettings::NativeFormat);
    
        settings = new QSettings("$HOME/.config/MySoft.ini",QSettings::IniFormat);
    
      // settings->setValue("ipcasa","192.168.1.8");
        if   (settings->contains("ipcasa"))
        {
            ip = settings->value("ipcasa").toString();
        }else {
    
            qDebug() << "insertr your Ip";
            emit statusChanged(" You must insert to Ip");
            
        }
    

    but I can't activate a messagedialog to warn the user that he has to insert the ip, I'm trying to do something like that but I have no idea how I can do:

    import QtQuick 2.0
    import QtQuick.Controls 2.5
    import QtQuick.Layouts 1.12
    import io.qt.Backend 1.0
    import QtQuick.Dialogs 1.3
    
    ApplicationWindow {
        id: window
           width: 500
           height: 500
    
        visible:true
    
       
    
        Backend{
            id: backend
    
            onStatusChanged: {
                messageDialog.setVisible(true);
    
                messageDialog.text = newStatus
    
            }
    
    
        }
        
        MessageDialog{
    
            id: messageDialog
                title: "Attention"
                onAccepted: {
                        console.log("message for insert ip start.")
                       // Qt.quit()
                    }
                   // Component.onCompleted: visible = true
                }
    
    

    Can you teach me how I could do?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Code looks OK. You do add backend to root context property of your QML engine, right?

      My suspicion is that you don't see the signal in QML because it is fired too early. You emit the signal in Backend constructor, so it is sent before you add it to QML engine, so also before there is Connections element.

      So, I think you should defer your initial status check for later, for example using QTimer::singleShot().

      (Z(:^

      Nio74N 1 Reply Last reply
      2
      • sierdzioS sierdzio

        Code looks OK. You do add backend to root context property of your QML engine, right?

        My suspicion is that you don't see the signal in QML because it is fired too early. You emit the signal in Backend constructor, so it is sent before you add it to QML engine, so also before there is Connections element.

        So, I think you should defer your initial status check for later, for example using QTimer::singleShot().

        Nio74N Offline
        Nio74N Offline
        Nio74
        wrote on last edited by
        #3

        you're right I'm checking before the backend class is instantiated, but to instantiate it I need the user to enter the ip address of the machine first, I'm thinking how to do it, I know I can't get it done from the backend class, I should do it do to another class? I'm a bit confused

        @sierdzio said in Signal from c++ for messagedialog on Qml:

        Code looks OK. You do add backend to root context property of your QML engine, right?

        My suspicion is that you don't see the signal in QML because it is fired too early. You emit the signal in Backend constructor, so it is sent before you add it to QML engine, so also before there is Connections element.

        So, I think you should defer your initial status check for later, for example using QTimer::singleShot().

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          In that case it sounds like you should introduce an uninitialized state to your backend. bool mInitialized = false;. Then add your backend to QML as usual, but make sure to check initialization in each method which is called before your user enters the IP address, like so:

          void Backend::someMethod() {
            if (mInitialized == false)
              return;
          
            // Your normal code
          }
          

          Then, when user does enter the IP address, call you method, create QSettings etc. and set mInitialized = true;.

          (Z(:^

          Nio74N 1 Reply Last reply
          2
          • sierdzioS sierdzio

            In that case it sounds like you should introduce an uninitialized state to your backend. bool mInitialized = false;. Then add your backend to QML as usual, but make sure to check initialization in each method which is called before your user enters the IP address, like so:

            void Backend::someMethod() {
              if (mInitialized == false)
                return;
            
              // Your normal code
            }
            

            Then, when user does enter the IP address, call you method, create QSettings etc. and set mInitialized = true;.

            Nio74N Offline
            Nio74N Offline
            Nio74
            wrote on last edited by
            #5

            tanks i am following your way

            @sierdzio said in Signal from c++ for messagedialog on Qml:

            In that case it sounds like you should introduce an uninitialized state to your backend. bool mInitialized = false;. Then add your backend to QML as usual, but make sure to check initialization in each method which is called before your user enters the IP address, like so:

            void Backend::someMethod() {
              if (mInitialized == false)
                return;
            
              // Your normal code
            }
            

            Then, when user does enter the IP address, call you method, create QSettings etc. and set mInitialized = true;.

            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