November 3, 2011

ditsikts ditsikts
Lab Rat
9 posts

populate treelist help

 

into my project search button doesnt work.
run my app, add an employee, add some data with different dates, use search.
You notice that when insert data treelist populate data. When use search, treelist didnt populate:(
http://www.megaupload.com/?d=Y2OJCBYV
Any help?

5 replies

November 4, 2011

Andre Andre
Robot Herder
6393 posts

Welcome to the forums.

Your description is very unclear. Please try to boil down your problem a bit more, you cannot expect the volunteers here to do your debugging work for you. What did you try before? What didn’t work?

note that your link doesn’t work (at least, not for me).

November 4, 2011

ditsikts ditsikts
Lab Rat
9 posts

sql select

  1. QSqlQuery wmtDB::searchGetwmData(QString name, int fromYear, int fromMonth, int fromDay, int toYear, int toMonth, int toDay){
  2.     QSqlQuery qry;
  3.     qry.prepare("SELECT * FROM workmoneydata WHERE name=(:name) AND year>=(:fromYear) AND year<=(:toYear) "
  4.                 "AND month>=(:fromMonth) AND month<=(:toMonth) AND day>=(:fromDay) AND day<=(:toDay) ORDER BY id DESC LIMIT 15");
  5.     qry.bindValue(":name", name);
  6.     qry.bindValue(":fromYear", fromYear);
  7.     qry.bindValue(":fromMonth", fromMonth);
  8.     qry.bindValue(":fromDay", fromDay);
  9.     qry.bindValue(":toYear", toYear);
  10.     qry.bindValue(":toMonth", toMonth);
  11.     qry.bindValue(":toDay", toDay);
  12.  
  13.     if (!qry.exec()){
  14.         qFatal("Failed to populate search list");
  15.     }
  16.     return qry;
  17. }

Function calls select

  1. void MainWindow::searchData(){
  2.     populateTreelist(employees.searchGetwmData(ui->comboBox->currentText(),ui->searchFromDateEdit->date().year(),
  3.                                                ui->searchFromDateEdit->date().month(),ui->searchFromDateEdit->date().day(),
  4.                                                ui->searchToDateEdit->date().year(),ui->searchToDateEdit->date().month(),
  5.                                                ui->searchToDateEdit->date().day()));
  6. }

function populate treelist

  1. void MainWindow::populateTreelist(QSqlQuery qry){
  2.     int i=0;
  3.     QString db_name,db_date, db_id,db_fromTime,db_toTime,db_Payment;
  4.  
  5.     QSImodel.clear();
  6.  
  7.     while (qry.next()){
  8.         db_name=qry.value(0).toString();
  9.         db_date=QDate(qry.value(3).toInt(),qry.value(2).toInt(),qry.value(1).toInt()).toString();
  10.         db_fromTime=QTime(qry.value(4).toInt(),qry.value(5).toInt()).toString();
  11.         db_toTime=QTime(qry.value(6).toInt(),qry.value(7).toInt()).toString();
  12.         db_Payment=qry.value(8).toString();
  13.         db_id=qry.value(9).toString();
  14.         QSImodel.setItem(i,0,new QStandardItem(db_name));
  15.         QSImodel.setItem(i,1,new QStandardItem(db_date));
  16.         QSImodel.setItem(i,2,new QStandardItem(db_fromTime));
  17.         QSImodel.setItem(i,3,new QStandardItem(db_toTime));
  18.         QSImodel.setItem(i,4,new QStandardItem(db_Payment));
  19.         QSImodel.setItem(i,5,new QStandardItem(db_id));
  20.         i++;
  21.     }
  22.  
  23.     QSImodel.setHeaderData(0,Qt::Horizontal,"name");
  24.     QSImodel.setHeaderData(1,Qt::Horizontal,"Date");
  25.     QSImodel.setHeaderData(2,Qt::Horizontal,"From");
  26.     QSImodel.setHeaderData(3,Qt::Horizontal,"To");
  27.     QSImodel.setHeaderData(4,Qt::Horizontal,"Payment");
  28.     QSImodel.setHeaderData(5,Qt::Horizontal,"id");
  29.     ui->treeView->setColumnHidden(0,true);
  30.     ui->treeView->setColumnHidden(5,true);
  31.     ui->treeView->setRootIsDecorated(false);
  32.     ui->treeView->setModel(&QSImodel);
  33.  
  34. }

treeview stay empty, dont even column headers added.
There is no error or warning.
QSImodel is a QStandardItemModel

one more link https://rapidshare.com/files/3781708727/wmtt.zip

November 4, 2011

Andre Andre
Robot Herder
6393 posts

Did you try runnning though a debugger, to see if your calls actually yield results? What is the result of your database query?

November 4, 2011

ditsikts ditsikts
Lab Rat
9 posts

How i use debugger?
Database query returns INSERTS between dates(searchFromDateEdit to serchToDateEdit)
Its weird because at begin was working.
If query was empty at least should set column headers…
populateTreelist function used by other QSqlQuery return functions and works fine.

November 4, 2011

ditsikts ditsikts
Lab Rat
9 posts

i put a qFatal error into

  1. while (qry.next()){...}
and seems doesnt enter into while when used by search query

 
  ‹‹ [solved] Exporting a QGraphicsView from one QFrame to another      [Solved] apple crash reporting ››

You must log in to post a reply. Not a member yet? Register here!