Results 1 to 4 of 4

Thread: application crushes after performing selectionModel() from tableView

  1. #1
    Join Date
    Oct 2008
    Location
    Dar es Salaam,Tanzania
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default application crushes after performing selectionModel() from tableView

    Hi guys,
    i'm trying to get a current selected row from a tableview so i can retrieve data from database edit them and update the database.i'm using QSqlTableModel and QTableView.
    When i run my application and push the editButton the application always crush,what seem to be a problem ,please help me here is the slot which cause the problem.

    Qt Code:
    1. void customers::on_pushButton_2_clicked()
    2. {
    3. const QModelIndexList list = m_ui->customerView->selectionModel()->selection().indexes();
    4. for (int i = 1; i < list.count(); i++)
    5. {
    6. QModelIndex index = list.at(i);
    7. int row = index.row();
    8. rows.insert(index.row());
    9. }
    10. qDebug() << row;
    11.  
    12.  
    13.  
    14. QSqlQuery query;
    15. query.exec(QString("SELECT * FROM customer where Id = row"));
    16. while (query.next()) {
    17.  
    18. db_id = query.value(0).toInt();
    19. db_LastName = query.value(1).toString();
    20. db_FirstName = query.value(2).toString();
    21. db_Category = query.value(3).toString();
    22. db_Amount = query.value(4).toString();
    23.  
    24.  
    25.  
    26. }
    27.  
    28.  
    29. dialog = new newCustomer(this);
    30. dialog->editCustomer(db_LastName);
    31. int accepted = dialog->exec();
    32. if(accepted == 1 )
    33. {
    34.  
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: application crushes after performing selectionModel() from tableView

    One of m_ui, m_ui->customerView or m_ui->customerView->selectionModel() is null or your list has less than two elements.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2008
    Location
    Dar es Salaam,Tanzania
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: application crushes after performing selectionModel() from tableView

    the qDebug << name<< row; shows that the list contains 4 items shown below,whis is second row in a table view

    "pop" 2
    "pop" 2
    "pop" 2
    "pop" 2

    but still the program crush .I modifies my code to one below here and i discovered that the "row" variable in a select statement is the one causing
    the application to crush.....

    Qt Code:
    1. void customers::on_pushButton_2_clicked()
    2. {
    3. int row;
    4. const QModelIndexList list = m_ui->customerView->selectionModel()->selection().indexes();
    5. for (int i = 1; i < list.count(); i++)
    6. {
    7. QModelIndex index = list.at(i);
    8. row = index.row();
    9. QString name = model->record(row).value("LastName").toString();
    10. qDebug() << name << row ;
    11. }
    12.  
    13.  
    14. QSqlQuery query;
    15. query.exec(QString("SELECT * FROM customer where Id = " + row)); //when i remove the variable "row" the crush stops
    16. while (query.next()) {
    17.  
    18. db_id = query.value(0).toInt();
    19. db_LastName = query.value(1).toString();
    20. db_FirstName = query.value(2).toString();
    21. db_Category = query.value(3).toString();
    22. db_Amount = query.value(4).toString();
    23.  
    24.  
    25.  
    26. }
    27.  
    28.  
    29. dialog = new newCustomer(this);
    30. dialog->editCustomer(db_LastName);
    31. int accepted = dialog->exec();
    32. if(accepted == 1 )
    33. {
    34.  
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: application crushes after performing selectionModel() from tableView

    You are adding an integer to a const char *. What effect do you think it has?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.