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. Populate treelist help
Forum Updated to NodeBB v4.3 + New Features

Populate treelist help

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

    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?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        ditsikts
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            ditsikts
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              ditsikts
              wrote on last edited by
              #6

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

              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