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. Problem with c++ to qml emiting

Problem with c++ to qml emiting

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 379 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.
  • A Offline
    A Offline
    Adamas
    wrote on last edited by
    #1

    Hi! I have some code. But I have problems with It. Cause I can't append to ListView something. When app start and starting changer() I have call of function, which emit signal to qml, but in qml nothing happens.

    In list view I have some pic+text+tooltip.

    main.cpp
     qmlRegisterType<changer>("Changer",1,0,"Changer");
    
    
    changer.cpp
    
    bool changer::add(std::string uid, QString name, QString place, QString type){
        place_uid.push_back(uid);
    
        emit adding(name,"0","good",place);
          qDebug() <<"pew-pew";
        return 1;
        }
     signals:
            void adding(QString idfromapp,QString data, QString sig, QString place);
    
    
    main.qml
    import Changer 1.0
    
     Changer{
       id: changeit
    
       }
       Connections {
           target: changeit
           onUpdate: {
                update(idbutt,idfromapp,data,sig,place)}
           onUpdateMeasure: {
               updateMeasure(idbutt,data,sig)
           }
           onRemove: {
               remove(idbutt)
           }
           onAdding: {
    
               add_component(idfromapp,data,sig,place)
    
           }
        }
    
    function add_component(idfromapp,data,sig,place){
           listMod.append({"attributes": [{"state":sig},{"textid":idfromapp},{"place":place},{"measure":data}]})
    }
    
    
    

    Can somebody e3xplain what I doing wrong?

    KroMignonK 1 Reply Last reply
    0
    • A Offline
      A Offline
      Adamas
      wrote on last edited by
      #3

      At least I solved It. The problem was in ListView. I need just write anchors.fill : parent, and now all work!

      1 Reply Last reply
      0
      • A Adamas

        Hi! I have some code. But I have problems with It. Cause I can't append to ListView something. When app start and starting changer() I have call of function, which emit signal to qml, but in qml nothing happens.

        In list view I have some pic+text+tooltip.

        main.cpp
         qmlRegisterType<changer>("Changer",1,0,"Changer");
        
        
        changer.cpp
        
        bool changer::add(std::string uid, QString name, QString place, QString type){
            place_uid.push_back(uid);
        
            emit adding(name,"0","good",place);
              qDebug() <<"pew-pew";
            return 1;
            }
         signals:
                void adding(QString idfromapp,QString data, QString sig, QString place);
        
        
        main.qml
        import Changer 1.0
        
         Changer{
           id: changeit
        
           }
           Connections {
               target: changeit
               onUpdate: {
                    update(idbutt,idfromapp,data,sig,place)}
               onUpdateMeasure: {
                   updateMeasure(idbutt,data,sig)
               }
               onRemove: {
                   remove(idbutt)
               }
               onAdding: {
        
                   add_component(idfromapp,data,sig,place)
        
               }
            }
        
        function add_component(idfromapp,data,sig,place){
               listMod.append({"attributes": [{"state":sig},{"textid":idfromapp},{"place":place},{"measure":data}]})
        }
        
        
        

        Can somebody e3xplain what I doing wrong?

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #2

        @Adamas Why do you use Connections ?

        It's more readable to declare signals connection direct on instance:

        import Changer 1.0
        
        Changer{
          id: changeit
        
          onUpdate: {
            update(idbutt,idfromapp,data,sig,place)
          }
          onUpdateMeasure: {
            updateMeasure(idbutt,data,sig)
          }
          onRemove: {
            remove(idbutt)
          }
          onAdding: {
            add_component(idfromapp,data,sig,place)
          }
        }
        
        function add_component(idfromapp,data,sig,place){
          listMod.append({"attributes": [{"state":sig},{"textid":idfromapp},{"place":place},{"measure":data}]})
        }
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        A 1 Reply Last reply
        0
        • A Offline
          A Offline
          Adamas
          wrote on last edited by
          #3

          At least I solved It. The problem was in ListView. I need just write anchors.fill : parent, and now all work!

          1 Reply Last reply
          0
          • KroMignonK KroMignon

            @Adamas Why do you use Connections ?

            It's more readable to declare signals connection direct on instance:

            import Changer 1.0
            
            Changer{
              id: changeit
            
              onUpdate: {
                update(idbutt,idfromapp,data,sig,place)
              }
              onUpdateMeasure: {
                updateMeasure(idbutt,data,sig)
              }
              onRemove: {
                remove(idbutt)
              }
              onAdding: {
                add_component(idfromapp,data,sig,place)
              }
            }
            
            function add_component(idfromapp,data,sig,place){
              listMod.append({"attributes": [{"state":sig},{"textid":idfromapp},{"place":place},{"measure":data}]})
            }
            
            A Offline
            A Offline
            Adamas
            wrote on last edited by
            #4

            @KroMignon

             listMod.append({"attributes": [{"state":sig},{"textid":idfromapp},{"place":place},{"measure":data}]})
            

            You know, In my struct it doesn't work. In this case it write only default attributes

            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