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. Changing SQL Value
Forum Updated to NodeBB v4.3 + New Features

Changing SQL Value

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 2.5k 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.
  • P Offline
    P Offline
    pemoamsi
    wrote on 1 Oct 2013, 12:46 last edited by
    #1

    Hy,

    I'm using the Relation Table Model Example, but I don't know witch is the location of the database and why I cannot find the itens there,

    How can I change to my "example.sqlite" as the source?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 1 Oct 2013, 14:14 last edited by
      #2

      Hi,

      IIRC the SQL examples uses in memory databases so there are no files there.

      Look at connection.h in the sql example folder

      Hope it helps

      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
      • P Offline
        P Offline
        pemoamsi
        wrote on 2 Oct 2013, 14:17 last edited by
        #3

        I've already changed this "db.setDatabaseName(":memory:");" to "db.setDatabaseName("example.sqlite");", but no lock yeat :(

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 2 Oct 2013, 19:57 last edited by
          #4

          Do you have example.sqlite in the same folder as your executable ?

          You have two options:

          • copy your example.sqlite in the same folder as your executable
          • give the complete path when calling setDatabaseName

          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
          • P Offline
            P Offline
            pemoamsi
            wrote on 4 Oct 2013, 15:42 last edited by
            #5

            @static bool createConnection()
            {
            QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
            db.setDatabaseName("t_job.sqlite");
            if (!db.open()) {
            QMessageBox::critical(0, qApp->tr("Cannot open database"),
            qApp->tr("Unable to establish a database connection.\n"
            "This example needs SQLite support. Please read "
            "the Qt SQL driver documentation for information how "
            "to build it.\n\n"
            "Click Cancel to exit."), QMessageBox::Cancel);
            return false;
            }

            QSqlQuery query;
            query.exec("create table examp (id int primary key, "
                       "firstname varchar(20), lastname varchar(20))");
            query.exec("insert into examp values(1, 'Ordem1.zip', '10:20')");
            query.exec("insert into examp values(2, 'Text', '12:00')");
            query.exec("insert into examp values(3, 'Low', '9:00')");
            query.exec("insert into examp values(1, 'c:wampfolder', '10:00')");
            query.exec("insert into examp values(2, '10.32.1.1Text', '11:00')");
            
            
            return true;
            

            }@

            I have all files in the right location but...
            I think my problem may be here:

            @TableEditor::TableEditor(const QString &myexample, QWidget *parent)
            : QWidget(parent)
            {
            model = new QSqlTableModel(this);
            //model->setTable(tableName);
            model->setTable(myexample);

            ...
            @

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 4 Oct 2013, 15:54 last edited by
              #6

              What does myexample contain ?

              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
              • P Offline
                P Offline
                pemoamsi
                wrote on 7 Oct 2013, 09:05 last edited by
                #7

                myexample is a Table with id, username, email and status

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 7 Oct 2013, 12:43 last edited by
                  #8

                  I meant what is the myexample variable value ?

                  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
                  • P Offline
                    P Offline
                    pemoamsi
                    wrote on 9 Oct 2013, 11:10 last edited by
                    #9

                    I think I didn't understand the question... variable values?

                    myexample is a table like this

                    ID | username | email | status
                    1 | pemo | pemo@mail.com | 1
                    2 | pe | pe@mail.com | 0
                    3 | pemoam | pemoam@mail.com | 1
                    4 | user | user@mail.com | 0
                    5 | newuser | newuser@mail.com | 1
                    5 | username | username@mail.com | 1

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 9 Oct 2013, 22:22 last edited by
                      #10

                      In your TableEditor constructor, you have the myexample parameter, what does it contain ?

                      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

                      3/10

                      2 Oct 2013, 14:17

                      topic:navigator.unread, 7
                      • Login

                      • Login or register to search.
                      3 out of 10
                      • First post
                        3/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved