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. Message Box

Message Box

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.6k 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.
  • M Offline
    M Offline
    MKSPulok
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • ZlatomirZ Offline
      ZlatomirZ Offline
      Zlatomir
      wrote on last edited by
      #2

      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?

      https://forum.qt.io/category/41/romanian

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MKSPulok
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MKSPulok
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • ZlatomirZ Offline
            ZlatomirZ Offline
            Zlatomir
            wrote on last edited by
            #5

            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.

            https://forum.qt.io/category/41/romanian

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MKSPulok
              wrote on last edited by
              #6

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

              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