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. Returning Value

Returning Value

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 717 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.
  • A Offline
    A Offline
    Adan895
    wrote on last edited by
    #1

    Hello Guys,

    Any clue on way this function could not be returning the required value?

    QString Registry::sendData()
    {
        QString data;
        QModelIndex index = ui->tableView->selectionModel()->currentIndex();
        QVariant value = index.siblingAtColumn(0).data();
        data = QVariant(value).toString();
    
        return data;
    }
    

    Thanks

    JKSHJ 1 Reply Last reply
    0
    • A Offline
      A Offline
      Adan895
      wrote on last edited by
      #7

      At the end, i figure it out using Singals and Slots, not an easy task, but after like 15 hours, i understood a little bit the logic and managed to use it, here is the code:

      void Registry::on_tableView_doubleClicked(const QModelIndex &index){
      
              Modify *Modi = new Modify();
              Modi->show();
              connect(this,SIGNAL(sendData(QString, int)),Modi,SLOT(receiveData(QString, int)));
              QString data = "";
              for (int c=0;c<=4;c++){
              QVariant value = index.siblingAtColumn(c).data();
              data = QVariant(value).toString();
              emit sendData(data, c);
       }
              this->close();
      }
      

      Thanks!

      jsulmJ 1 Reply Last reply
      0
      • A Adan895

        Hello Guys,

        Any clue on way this function could not be returning the required value?

        QString Registry::sendData()
        {
            QString data;
            QModelIndex index = ui->tableView->selectionModel()->currentIndex();
            QVariant value = index.siblingAtColumn(0).data();
            data = QVariant(value).toString();
        
            return data;
        }
        

        Thanks

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by JKSH
        #2

        @Adan895 said in Returning Value:

        Any clue on way this function could not be returning the required value?

        Insert this into your function to find a clue:

        qDebug() << value;
        qDebug() << QVariant(value);
        qDebug() << data;
        qDebug() << QVariant(value).toString();
        qDebug() << value.toString();
        

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        A 1 Reply Last reply
        5
        • JKSHJ JKSH

          @Adan895 said in Returning Value:

          Any clue on way this function could not be returning the required value?

          Insert this into your function to find a clue:

          qDebug() << value;
          qDebug() << QVariant(value);
          qDebug() << data;
          qDebug() << QVariant(value).toString();
          qDebug() << value.toString();
          
          A Offline
          A Offline
          Adan895
          wrote on last edited by Adan895
          #3

          @JKSH Hello , this is the output :C, i also added the INDEX and apparently is giving an invalid output:

          22:28:34: Starting /home/adan/build-Groostore-Desktop_Qt_5_12_6_GCC_64bit-Debug/Groostore ...
          QModelIndex(-1,-1,0x0,QObject(0x0))
          QVariant(Invalid)
          QVariant(Invalid)
          ""
          ""
          
          1 Reply Last reply
          0
          • A Offline
            A Offline
            Astrinus
            wrote on last edited by
            #4

            currentIndex is invalid, hence the model returns an invalid value.

            A 1 Reply Last reply
            0
            • A Astrinus

              currentIndex is invalid, hence the model returns an invalid value.

              A Offline
              A Offline
              Adan895
              wrote on last edited by
              #5

              @Astrinus the question is why the Index is invalid, as i am using the exact same code on other Slots working perfectly.

              JKSHJ 1 Reply Last reply
              0
              • A Adan895

                @Astrinus the question is why the Index is invalid, as i am using the exact same code on other Slots working perfectly.

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #6

                @Adan895 said in Returning Value:

                the question is why the Index is invalid, as i am using the exact same code on other Slots working perfectly.

                1. What have you selected in the table view when sendData() is called?
                2. What have you selected in the table view when the other slot is called?

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Adan895
                  wrote on last edited by
                  #7

                  At the end, i figure it out using Singals and Slots, not an easy task, but after like 15 hours, i understood a little bit the logic and managed to use it, here is the code:

                  void Registry::on_tableView_doubleClicked(const QModelIndex &index){
                  
                          Modify *Modi = new Modify();
                          Modi->show();
                          connect(this,SIGNAL(sendData(QString, int)),Modi,SLOT(receiveData(QString, int)));
                          QString data = "";
                          for (int c=0;c<=4;c++){
                          QVariant value = index.siblingAtColumn(c).data();
                          data = QVariant(value).toString();
                          emit sendData(data, c);
                   }
                          this->close();
                  }
                  

                  Thanks!

                  jsulmJ 1 Reply Last reply
                  0
                  • A Adan895

                    At the end, i figure it out using Singals and Slots, not an easy task, but after like 15 hours, i understood a little bit the logic and managed to use it, here is the code:

                    void Registry::on_tableView_doubleClicked(const QModelIndex &index){
                    
                            Modify *Modi = new Modify();
                            Modi->show();
                            connect(this,SIGNAL(sendData(QString, int)),Modi,SLOT(receiveData(QString, int)));
                            QString data = "";
                            for (int c=0;c<=4;c++){
                            QVariant value = index.siblingAtColumn(c).data();
                            data = QVariant(value).toString();
                            emit sendData(data, c);
                     }
                            this->close();
                    }
                    

                    Thanks!

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @Adan895 said in Returning Value:

                    Modi

                    You're leaking this as you don't delete it

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    A 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @Adan895 said in Returning Value:

                      Modi

                      You're leaking this as you don't delete it

                      A Offline
                      A Offline
                      Adan895
                      wrote on last edited by
                      #9

                      @jsulm which will be the way to delete it?

                      Delete Modi;
                      

                      Sorry i didnt know i have to delete it.

                      ODБOïO 1 Reply Last reply
                      0
                      • A Adan895

                        @jsulm which will be the way to delete it?

                        Delete Modi;
                        

                        Sorry i didnt know i have to delete it.

                        ODБOïO Offline
                        ODБOïO Offline
                        ODБOï
                        wrote on last edited by
                        #10

                        @Adan895 hi

                        someone will correct me if i'm wrong, just call

                        Modi->deleteLater();
                        
                        A 1 Reply Last reply
                        0
                        • ODБOïO ODБOï

                          @Adan895 hi

                          someone will correct me if i'm wrong, just call

                          Modi->deleteLater();
                          
                          A Offline
                          A Offline
                          Adan895
                          wrote on last edited by
                          #11

                          @LeLev Okay, i will use it from now on :)

                          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