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. [solved] - qdateedit editingfinished signal problem
Forum Updated to NodeBB v4.3 + New Features

[solved] - qdateedit editingfinished signal problem

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.3k 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.
  • A Offline
    A Offline
    angelicaP
    wrote on last edited by
    #1

    have you experienced the following issue?

    this is my code:

    @void log::on_dateEdit_editingFinished()
    {
    QSqlDatabase h = QSqlDatabase::database("connection");
    if (h.open())
    {
    QSqlQuery q1(h);
    q1.prepare("SELECT * FROM log WHERE date>=:date1 AND date <=:date2 ORDER BY date ASC");
    q1.bindValue(":date1" ,ui->date1->text());
    q1.bindValue(":date2" ,ui->date2->text());
    q1.exec();
    QSqlQueryModel *mq1= new QSqlQueryModel();
    mq1->setQuery(q1);
    ui->tableView->setModel(mq1);
    }
    else
    {
    qDebug() << "connection is not opened" << h.lastError();
    }
    h.close();
    }@

    1st time i run my application, after I edit date 2, the info is displayed correctly in my tableview.
    if i close the session and run 2nd time the application, the query is not performed, or for some other reason no info is displayed in my tableview.

    have you experienced anything like this?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Seba84
      wrote on last edited by
      #2

      What is the debug output you've got with h.lastError()?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        angelicaP
        wrote on last edited by
        #3

        no error message, meaning the connection is opened.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You should also check that q1.exec() returns successfully

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            angelicaP
            wrote on last edited by
            #5

            Hi,

            query returns successfully from Qt and PostgreSQL with required fields - values substitution. as mentioned, when i run 1st time after reboot the application, the query returns the correct values and tableview displays them.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Seba84
              wrote on last edited by
              #6

              I don't understand exactly the situation with all the rebooting and excetera; but I think it is strange you close the database connection at the end of the function. Isn't that your problem?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                angelicaP
                wrote on last edited by
                #7

                issue solved:

                @ ...
                q1.bindValue(":date1" ,ui->date1->text());
                q1.bindValue(":date2" ,ui->date2->text());
                ...@

                should be: date() instead of text(), I guess the query will not consider the text as date.
                correct code:
                @...
                q1.bindValue(":date1" ,ui->date1->date());
                q1.bindValue(":date2" ,ui->date2->date());
                ...@

                thank you all for your input.

                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