Results 1 to 3 of 3

Thread: Extracting data from appended row

  1. #1
    Join Date
    Aug 2011
    Location
    The Internet
    Posts
    29
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Extracting data from appended row

    I am trying to grab a specific part of a row upon selection and send the data as the original data type it was (uint32_t). Here are the pieces of code relevant:

    Qt Code:
    1. QList<QStandardItem *> MainWindow::prepareRow(uint32_t ID, const QString &first, const QString &second, const QString &third)
    2. {
    3. QList<QStandardItem *> rowItems;
    4. QStandardItem *ptr = new QStandardItem(first);
    5. rowItems << ptr;
    6. ptr = new QStandardItem(second);
    7. rowItems << ptr;
    8. ptr = new QStandardItem(third);
    9. rowItems << ptr;
    10.  
    11. QString tmp;
    12. QTextStream uniquetmp(&tmp);
    13. uniquetmp << ID;
    14.  
    15. ptr = new QStandardItem(tmp);
    16. rowItems << ptr;
    17.  
    18. return rowItems;
    19. }
    To copy to clipboard, switch view to plain text mode 
    that's how I am placing ID in

    Qt Code:
    1. void MainWindow::alarm(uint32_t UniqueID, DateTimeType EventTime, QString Hosts, QString Name)
    2. {
    3. QString tmp;
    4. QTextStream event_time(&tmp);
    5. event_time.setFieldWidth(1);
    6. event_time << EvenTime.Hour << QString(":") << EventTime.Min << QString(":") << EventTime.Sec;
    7.  
    8. bool found= false;
    9. std::vector<iterator it = Alarms.begin();
    10. while (it != Alarms.end())
    11. {
    12. std::string temp1 = Name.toLatin1();
    13. std::string temp2 = it->name;
    14. if (Name.compare(it->name.c_str()) == 0)
    15. {
    16. found = true;
    17. break;
    18. }
    19. }
    20. if (found)
    21. {
    22. QList<QStandardItem *> preparedRow = prepareRow(ID, tmp, HostName, it->brief.c_str());
    23. QStandardItem *itemd1 = standardModel->invisibleRootItem();
    24. itemd1->appendRow(preparedRow);
    25. }
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 

    Now I'm trying to remove a specific row with the following function. Upon removing it, I want to get ID back and into type uint32_t. Any suggestions?
    Qt Code:
    1. void MainWindow::Remove()
    2. {
    3. QItemSelectionModel *selected = ui.view->selectionModel();
    4. QModelIndexList rowList = selected->selectedRows();
    5.  
    6. foreach(QModelIndex rowIndex, rowList) {
    7. standardModel->removeRow(rowIndex.row(), rowIndex.parent());
    8.  
    9. //I'm guessing i want to grab it here? Don't know how to specify that I only want ID and want to convert to uint32_t
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,630
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Extracting data from appended row

    QVariant::toUInt() seems a likely candidate if you use data() to get the value, or QString::toUint()/toULong() if you use text().

  3. #3
    Join Date
    Aug 2011
    Location
    The Internet
    Posts
    29
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extracting data from appended row

    Thanks I will try that out and let you know!

Similar Threads

  1. Extracting QT translations from sources
    By mcosta in forum Installation and Deployment
    Replies: 3
    Last Post: 26th April 2010, 17:28
  2. Extracting int values from QByteArray
    By Tottish in forum Newbie
    Replies: 4
    Last Post: 7th April 2010, 10:41
  3. Extracting text from QTableWidgetItem
    By bizmopeen in forum Newbie
    Replies: 3
    Last Post: 1st September 2009, 17:28
  4. Extracting xml fragment from QXmlStreamReader
    By Gopala Krishna in forum Qt Programming
    Replies: 5
    Last Post: 1st December 2007, 09:14
  5. Values not being appended in a QList
    By Kapil in forum Newbie
    Replies: 5
    Last Post: 21st April 2006, 10:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.