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

Returning Value



  • 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



  • 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!


  • Moderators

    @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();
    


  • @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)
    ""
    ""
    


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



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


  • Moderators

    @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?


  • 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!


  • Lifetime Qt Champion

    @Adan895 said in Returning Value:

    Modi

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



  • @jsulm which will be the way to delete it?

    Delete Modi;
    

    Sorry i didnt know i have to delete it.



  • @Adan895 hi

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

    Modi->deleteLater();
    


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


Log in to reply