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!
-
@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) "" ""
-
@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.
- What have you selected in the table view when
sendData()
is called? - What have you selected in the table view when the other slot is called?
- What have you selected in the table view when
-
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!
-