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?



  • 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).



  • sql select
    @QSqlQuery wmtDB::searchGetwmData(QString name, int fromYear, int fromMonth, int fromDay, int toYear, int toMonth, int toDay){
    QSqlQuery qry;
    qry.prepare("SELECT * FROM workmoneydata WHERE name=(:name) AND year>=(:fromYear) AND year<=(:toYear) "
    "AND month>=(:fromMonth) AND month<=(:toMonth) AND day>=(:fromDay) AND day<=(:toDay) ORDER BY id DESC LIMIT 15");
    qry.bindValue(":name", name);
    qry.bindValue(":fromYear", fromYear);
    qry.bindValue(":fromMonth", fromMonth);
    qry.bindValue(":fromDay", fromDay);
    qry.bindValue(":toYear", toYear);
    qry.bindValue(":toMonth", toMonth);
    qry.bindValue(":toDay", toDay);

    if (!qry.exec&#40;&#41;){
        qFatal("Failed to populate search list");
    }
    return qry;
    

    }@

    Function calls select
    @void MainWindow::searchData(){
    populateTreelist(employees.searchGetwmData(ui->comboBox->currentText(),ui->searchFromDateEdit->date().year(),
    ui->searchFromDateEdit->date().month(),ui->searchFromDateEdit->date().day(),
    ui->searchToDateEdit->date().year(),ui->searchToDateEdit->date().month(),
    ui->searchToDateEdit->date().day()));
    }@

    function populate treelist
    @void MainWindow::populateTreelist(QSqlQuery qry){
    int i=0;
    QString db_name,db_date, db_id,db_fromTime,db_toTime,db_Payment;

    QSImodel.clear();
    
    while (qry.next()){
        db_name=qry.value(0).toString();
        db_date=QDate(qry.value(3).toInt(),qry.value(2).toInt(),qry.value(1).toInt()).toString();
        db_fromTime=QTime(qry.value(4).toInt(),qry.value(5).toInt()).toString();
        db_toTime=QTime(qry.value(6).toInt(),qry.value(7).toInt()).toString();
        db_Payment=qry.value(8).toString();
        db_id=qry.value(9).toString();
        QSImodel.setItem(i,0,new QStandardItem(db_name));
        QSImodel.setItem(i,1,new QStandardItem(db_date));
        QSImodel.setItem(i,2,new QStandardItem(db_fromTime));
        QSImodel.setItem(i,3,new QStandardItem(db_toTime));
        QSImodel.setItem(i,4,new QStandardItem(db_Payment));
        QSImodel.setItem(i,5,new QStandardItem(db_id));
        i++;
    }
    
    QSImodel.setHeaderData(0,Qt::Horizontal,"name");
    QSImodel.setHeaderData(1,Qt::Horizontal,"Date");
    QSImodel.setHeaderData(2,Qt::Horizontal,"From");
    QSImodel.setHeaderData(3,Qt::Horizontal,"To");
    QSImodel.setHeaderData(4,Qt::Horizontal,"Payment");
    QSImodel.setHeaderData(5,Qt::Horizontal,"id");
    ui->treeView->setColumnHidden(0,true);
    ui->treeView->setColumnHidden(5,true);
    ui->treeView->setRootIsDecorated(false);
    ui->treeView->setModel(&QSImodel);
    

    }@

    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



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



  • 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.



  • i put a qFatal error into @while (qry.next()){...}@ and seems doesnt enter into while when used by search query


Log in to reply
 

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