Message Box



  • Hi I.ve the following function for deleting an Item from my Dialog box
    @void TnFSimulatorAssetTypeEditorDlg::onClickDeleteData()
    {
    QModelIndex index = ui->m_tableViewType->currentIndex();

    if(!index.isValid()) return;
    
    int nSelectedRow = index.row();
    
    if(nSelectedRow >= 0)
    {
        QStandardItem* pStdItemId = m_pItemModel->item(nSelectedRow,0);
        QString strItemId = pStdItemId->text().trimmed();
    
        if(TnFSimulatorMessageController::getInstance()->showMessage("Delete selected Type..","Are you sure?",
                                   QMessageBox::Question,QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
        {
            return;
        }
    
        QString strQuery = QString("DELETE from %0 where id=%1").arg(m_strTableName).arg(strItemId.toInt());
        TnFSimulatorSqlQuery* query = TnFSimulatorDB::getInstance()->executeTnFSqlQuery(strQuery, false);
    
        if(query)
        {
            m_pItemModel->removeRow(nSelectedRow);
            ui->m_tableViewType->selectRow(ui->m_tableViewType->currentIndex().row());
    
            emit dataChanged();
        }
    
        else
        {
            TnFSimulatorMessageController::getInstance()->showMessage("Delete Type Failed...",
                                    "Delete Erorr.",
                                    QMessageBox::Critical);
            return;
        }
    }
    

    }
    @

    but I want to give message except that "Delete selected Type..","Are you sure?" except that Specific Item name would be shown to the user Like that "Are you sure want to delete Item name ?"

    how can I do this can anyone plz help me



  • I didn't understand what is your problem, so your issue is that you don't know how to extract get that "name"?
    Do you need info from the Name column not from ID column?
    @
    QStandardItem* pStdItemName = m_pItemModel->item(nSelectedRow, 1); //replace 1 with the name column index
    QString strItemName = pStdItemName->text().trimmed();
    @
    Or you have the name and you don't know how to format the string? You can use the arg method:
    @... QString("Are you sure want to delete %1").arg(strItemName) ...@

    So, tell us more about your data, especially what is that name and where it's stored?



  • Actually I don have any name and I want to generate name and also to use it.



  • I used

    @ QStandardItem* pStdItemName = m_pItemModel->item(nSelectedRow, 1);@

    @ QString strItemName = pStdItemId->text().trimmed();@

    and also
    @ QString("Are you sure want to delete %1").arg(strItemName) @

    bt it gives error
    1.pStdItemName was not declare in the scope
    2.No matching found TnFSimulatorMessageController::show message function



  • Why would you do that if the name is not a column, i assumed you have the name in the next column after the ID, so ignore that.

    So, the magic name, what is that name, just decide and then use the .arg member function to format the string you pass to the messagebox.



  • ya finally I found the name and it's work .thanks to u for co-operating


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.