Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Advice about the application I will be making? (I'm a beginner)
Forum Updated to NodeBB v4.3 + New Features

Advice about the application I will be making? (I'm a beginner)

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
77 Posts 6 Posters 26.6k Views 2 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #58

    hi
    are you sure the table name is mydatabase ?
    seems wrong. unless the table is called taht.
    But it seems you used the name of the database.

    and it even says unknown table.
    so use table name instead.

    1 Reply Last reply
    3
    • D dvlpr.bernard

      0_1556685583290_a11aff6b-ff9a-4e92-828b-3de115afe4c9-image.png

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #59

      @dvlpr.bernard

      no such table: mydatabase

      @mrjj wrote:

      are you sure the table name is mydatabase ?

      Are you getting your database vs your tables mixed up in your head? You work with one database at a time. In SQLite that corresponds to the file you pass to setDatabaseName(), and is what gets opened via mydb.open(). A database may contain many tables, each with their own name. It is the table name you mention in SQL select (and most other) statements. You previously created your table(s) via some kind of CREATE TABLE name ... statement, and that name is what you need in your query. It would be "unusual" for you to have named a table mydatabase.

      You might like to do yourself a favour, to help with all the SQLite queries you're trying to write. Download one of the (free) "workbenches" for SQLite. These are GUI applications which will let you see what is in your database; it will also let you construct and play with queries, till you are ready to copy them over to your Qt code. Google for sqlite workbench, there seem to be several, e.g. https://www.sqlite-workbench.com/, https://sqlitestudio.pl, https://alternativeto.net/software/sqlite-manager/. I suggest you take the time to pick one, in the long run I think the effort will be well worthwhile for you.

      1 Reply Last reply
      2
      • D Offline
        D Offline
        dvlpr.bernard
        wrote on last edited by
        #60

        Good day.
        So here is my database named codeanaldb with a table name "mydatabase". I didn't know why qt couldn't recognize it.

        0_1556721420905_3aa67a8d-a82e-4456-9548-1500489ec844-image.png

        And here is the same query that I copy paste to qt but suddenly didn't work.

        0_1556721664803_4baa7258-307d-4a59-9dbb-68db56cb80f8-image.png

        JonBJ 1 Reply Last reply
        0
        • D dvlpr.bernard

          Good day.
          So here is my database named codeanaldb with a table name "mydatabase". I didn't know why qt couldn't recognize it.

          0_1556721420905_3aa67a8d-a82e-4456-9548-1500489ec844-image.png

          And here is the same query that I copy paste to qt but suddenly didn't work.

          0_1556721664803_4baa7258-307d-4a59-9dbb-68db56cb80f8-image.png

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #61

          @dvlpr.bernard
          In a word, Qt will "accept" any SQL query you can make work in a workbench. If it isn't something else is wrong, e.g. you're not connected to the database you think you are....

          1 Reply Last reply
          1
          • D dvlpr.bernard

            0_1556685583290_a11aff6b-ff9a-4e92-828b-3de115afe4c9-image.png

            KillerSmathK Offline
            KillerSmathK Offline
            KillerSmath
            wrote on last edited by
            #62

            @dvlpr.bernard said in Advice about the application I will be making? (I'm a beginner):

            0_1556685583290_a11aff6b-ff9a-4e92-828b-3de115afe4c9-image.png

            Are you sure that your database file is Database codeanaldb ? Because in last image you have used Database codeanal.db (with .)

            @Computer Science Student - Brazil
            Web Developer and Researcher
            “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

            1 Reply Last reply
            2
            • D Offline
              D Offline
              dvlpr.bernard
              wrote on last edited by dvlpr.bernard
              #63

              Holly cow, after more than a 100 trial and error, I got it guys. So the problem is I didn't set the path correctly but I'm pretty sure I set it correctly earlier but then other code wasn't correct so I played around and tried change the path, I don't know why it is still working even if the path is wrong. So thank you again guys :).

              Correct One: - connected and query is worling
              mydb.setDatabaseName("C:\Users\bj\Documents\CODEANALL\Database\codeanaldb1.db");
              Wrong One: - connected but the query isn't working dunno why
              mydb.setDatabaseName("C:\Users\bj\Documents\CODEANALL\Database codeanaldb1.db");

              0_1556722834541_bdf923ef-e973-41f0-ae89-f8e84f224c65-image.png

              JonBJ KillerSmathK 2 Replies Last reply
              0
              • D dvlpr.bernard

                Holly cow, after more than a 100 trial and error, I got it guys. So the problem is I didn't set the path correctly but I'm pretty sure I set it correctly earlier but then other code wasn't correct so I played around and tried change the path, I don't know why it is still working even if the path is wrong. So thank you again guys :).

                Correct One: - connected and query is worling
                mydb.setDatabaseName("C:\Users\bj\Documents\CODEANALL\Database\codeanaldb1.db");
                Wrong One: - connected but the query isn't working dunno why
                mydb.setDatabaseName("C:\Users\bj\Documents\CODEANALL\Database codeanaldb1.db");

                0_1556722834541_bdf923ef-e973-41f0-ae89-f8e84f224c65-image.png

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #64

                @dvlpr.bernard

                Correct One: - connected and query is worling
                mydb.setDatabaseName("C:\Users\bj\Documents\CODEANALL\Database\codeanaldb1.db");
                Wrong One: - connected but the query isn't working dunno why
                mydb.setDatabaseName("C:\Users\bj\Documents\CODEANALL\Database codeanaldb1.db");

                I suspect (never having used SQLite) that your existing database is the first path. When you specify the second path to open(), being non-existent SQLite decides to create that for you, as an empty database, which then does not have the table mentioned in the query/error message. Check your disk (directly in the CODEANALL folder) to see if the second one exists, or exists so long as you are running the query?

                If that is the case, there "must" be some way of asking to open only an existent database/file from SQLite/Qt which you could use for safety?

                1 Reply Last reply
                1
                • D dvlpr.bernard

                  Holly cow, after more than a 100 trial and error, I got it guys. So the problem is I didn't set the path correctly but I'm pretty sure I set it correctly earlier but then other code wasn't correct so I played around and tried change the path, I don't know why it is still working even if the path is wrong. So thank you again guys :).

                  Correct One: - connected and query is worling
                  mydb.setDatabaseName("C:\Users\bj\Documents\CODEANALL\Database\codeanaldb1.db");
                  Wrong One: - connected but the query isn't working dunno why
                  mydb.setDatabaseName("C:\Users\bj\Documents\CODEANALL\Database codeanaldb1.db");

                  0_1556722834541_bdf923ef-e973-41f0-ae89-f8e84f224c65-image.png

                  KillerSmathK Offline
                  KillerSmathK Offline
                  KillerSmath
                  wrote on last edited by KillerSmath
                  #65

                  @dvlpr.bernard

                  I don't know why it is still working even if the path is wrong.

                  it is because, the QSqliteDriver uses by default, SQLITE_OPEN_CREATE flag to create the file if it is not exists.

                  @Computer Science Student - Brazil
                  Web Developer and Researcher
                  “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                  JonBJ 1 Reply Last reply
                  3
                  • KillerSmathK KillerSmath

                    @dvlpr.bernard

                    I don't know why it is still working even if the path is wrong.

                    it is because, the QSqliteDriver uses by default, SQLITE_OPEN_CREATE flag to create the file if it is not exists.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #66

                    @KillerSmath
                    Then the question is: can you specify something at open() time to override that behaviour, without changing the driver? Or, can you temporarily change that driver flag from code before opening? Then the OP would have found out/use it in future.

                    Meanwhile, the OP needs to understand that the two paths (one with space, one with backslash) refer to quite different files!

                    D KillerSmathK 2 Replies Last reply
                    1
                    • JonBJ JonB

                      @KillerSmath
                      Then the question is: can you specify something at open() time to override that behaviour, without changing the driver? Or, can you temporarily change that driver flag from code before opening? Then the OP would have found out/use it in future.

                      Meanwhile, the OP needs to understand that the two paths (one with space, one with backslash) refer to quite different files!

                      D Offline
                      D Offline
                      dvlpr.bernard
                      wrote on last edited by dvlpr.bernard
                      #67

                      I see so that's the reason why there is a newly created database in my folder. Also backslash "\" specifies the parent folder. I have encountered that on web dev. Thank you!

                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @KillerSmath
                        Then the question is: can you specify something at open() time to override that behaviour, without changing the driver? Or, can you temporarily change that driver flag from code before opening? Then the OP would have found out/use it in future.

                        Meanwhile, the OP needs to understand that the two paths (one with space, one with backslash) refer to quite different files!

                        KillerSmathK Offline
                        KillerSmathK Offline
                        KillerSmath
                        wrote on last edited by
                        #68

                        @JonB
                        Your answer is on sqlite source code.

                        Unhapply, that behaviour is only avoided if you are using SQLITE_OPEN_READONLY flag

                        @Computer Science Student - Brazil
                        Web Developer and Researcher
                        “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                        JonBJ 1 Reply Last reply
                        3
                        • KillerSmathK KillerSmath

                          @JonB
                          Your answer is on sqlite source code.

                          Unhapply, that behaviour is only avoided if you are using SQLITE_OPEN_READONLY flag

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by JonB
                          #69

                          @KillerSmath
                          Then @dvlpr-bernard might want to do a QFile::exists() check on the filepath prior to the open() if he wants to ensure he is opening a correctly-spelled existing database rather than accidentally creating a blank new one....

                          1 Reply Last reply
                          3
                          • D Offline
                            D Offline
                            dvlpr.bernard
                            wrote on last edited by
                            #70

                            I tried different code but it didn't work. What should I do to replace query variable value with my variable in qt.
                            "select Answer from mydatabase where QQuantity = 5 and Topic = 'FOR' and Difficulty_Level = 'ADVANCED'"
                            0_1556809488139_40bef343-e9e0-41ad-bb2e-070a5789455e-image.png

                            KroMignonK 1 Reply Last reply
                            0
                            • D dvlpr.bernard

                              I tried different code but it didn't work. What should I do to replace query variable value with my variable in qt.
                              "select Answer from mydatabase where QQuantity = 5 and Topic = 'FOR' and Difficulty_Level = 'ADVANCED'"
                              0_1556809488139_40bef343-e9e0-41ad-bb2e-070a5789455e-image.png

                              KroMignonK Offline
                              KroMignonK Offline
                              KroMignon
                              wrote on last edited by KroMignon
                              #71

                              @dvlpr.bernard This should work:

                              query.prepare("select answer from mydatabase where QQuantitiy=:qquantity AND Topic =:topic and Difficulty_Level =:difficulty_level")
                              query.bindValue(":qquantity", current_num);
                              query.bindValue(":topic", ch_topic);
                              query.bindValue(":difficulty_level", ch_div_lvl);
                              

                              binValue will add necessary escape sequencies for string values.
                              you only have to ensure placeholder in prepare string is the same as which given to bindValue().

                              Read QSqlQuery Class for more details.

                              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                              D 1 Reply Last reply
                              4
                              • KroMignonK KroMignon

                                @dvlpr.bernard This should work:

                                query.prepare("select answer from mydatabase where QQuantitiy=:qquantity AND Topic =:topic and Difficulty_Level =:difficulty_level")
                                query.bindValue(":qquantity", current_num);
                                query.bindValue(":topic", ch_topic);
                                query.bindValue(":difficulty_level", ch_div_lvl);
                                

                                binValue will add necessary escape sequencies for string values.
                                you only have to ensure placeholder in prepare string is the same as which given to bindValue().

                                Read QSqlQuery Class for more details.

                                D Offline
                                D Offline
                                dvlpr.bernard
                                wrote on last edited by dvlpr.bernard
                                #72

                                @KroMignon
                                It is working now there is just a misspelled word QQuantitiy to QQuantity. Thank you sir :)

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  dvlpr.bernard
                                  wrote on last edited by
                                  #73

                                  Good day!

                                  I got strange spacing whenever I get a question from my database.
                                  Before I paste to the database:
                                  0_1556893610379_c08bd5fe-6b99-41af-86c7-7baba4f004f8-image.png

                                  After I executed the query
                                  0_1556893684717_cfe98f8b-b909-4343-b680-0b3131f0226a-image.png

                                  Sir @mrjj you mentioned earlier that I can make it look more like a code in a text editor. Like so
                                  0_1556894107853_0cffa870-6b69-4959-9ffe-7b936a3595ab-image.png
                                  How is that?

                                  KillerSmathK 1 Reply Last reply
                                  0
                                  • D dvlpr.bernard

                                    Good day!

                                    I got strange spacing whenever I get a question from my database.
                                    Before I paste to the database:
                                    0_1556893610379_c08bd5fe-6b99-41af-86c7-7baba4f004f8-image.png

                                    After I executed the query
                                    0_1556893684717_cfe98f8b-b909-4343-b680-0b3131f0226a-image.png

                                    Sir @mrjj you mentioned earlier that I can make it look more like a code in a text editor. Like so
                                    0_1556894107853_0cffa870-6b69-4959-9ffe-7b936a3595ab-image.png
                                    How is that?

                                    KillerSmathK Offline
                                    KillerSmathK Offline
                                    KillerSmath
                                    wrote on last edited by
                                    #74

                                    @dvlpr.bernard

                                    I got strange spacing whenever I get a question from my database.
                                    Before I paste to the database:
                                    0_1556893610379_c08bd5fe-6b99-41af-86c7-7baba4f004f8-image.png

                                    After I executed the query
                                    0_1556893684717_cfe98f8b-b909-4343-b680-0b3131f0226a-image.png

                                    Are you using "raw" or tabulation spaces to indent your example codes ?

                                    @mrjj has mentioned the QSyntaxHighlighter

                                    @Computer Science Student - Brazil
                                    Web Developer and Researcher
                                    “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                                    D 1 Reply Last reply
                                    1
                                    • KillerSmathK KillerSmath

                                      @dvlpr.bernard

                                      I got strange spacing whenever I get a question from my database.
                                      Before I paste to the database:
                                      0_1556893610379_c08bd5fe-6b99-41af-86c7-7baba4f004f8-image.png

                                      After I executed the query
                                      0_1556893684717_cfe98f8b-b909-4343-b680-0b3131f0226a-image.png

                                      Are you using "raw" or tabulation spaces to indent your example codes ?

                                      @mrjj has mentioned the QSyntaxHighlighter

                                      D Offline
                                      D Offline
                                      dvlpr.bernard
                                      wrote on last edited by
                                      #75

                                      @KillerSmath
                                      I was using the tabulation spaces to indent. I thought that was the problem so I tried the raw tabulation or using the spacebar but I still got the same result.

                                      KillerSmathK 1 Reply Last reply
                                      0
                                      • D dvlpr.bernard

                                        @KillerSmath
                                        I was using the tabulation spaces to indent. I thought that was the problem so I tried the raw tabulation or using the spacebar but I still got the same result.

                                        KillerSmathK Offline
                                        KillerSmathK Offline
                                        KillerSmath
                                        wrote on last edited by KillerSmath
                                        #76

                                        @dvlpr.bernard
                                        I am not sure if you can directly change the tab stop size in QLabel.
                                        A possible way, since you are using tab spaces to indent your code, would be replace all tabs by raw spaces.

                                        QString string = "#include <iostream>\n#include <stdlib>\n\nint main(){\n\tbool x;\n}";
                                        string.replace('\t', QLatin1String("    ")); // 4 raw spaces
                                        label->setText(string);
                                        

                                        However, QTextEdit has the feature to change the TabSize and it is the default widget used by QSyntaxHighlighter.

                                        @Computer Science Student - Brazil
                                        Web Developer and Researcher
                                        “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                                        1 Reply Last reply
                                        1
                                        • mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #77

                                          Hi
                                          You can take the highlighter from here
                                          https://doc.qt.io/qt-5/qtwidgets-richtext-syntaxhighlighter-example.html
                                          (the sample is in creator already )
                                          and instead of having the question code in a QLabel, use TextEdit as @KillerSmath says.

                                          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