Unsolved Advice about the application I will be making? (I'm a beginner)
-
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.
-
@KillerSmath
Then the question is: can you specify something atopen()
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!
-
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!
-
@JonB
Your answer is on sqlite source code.Unhapply, that behaviour is only avoided if you are using SQLITE_OPEN_READONLY flag
-
@KillerSmath
Then @dvlpr-bernard might want to do aQFile::exists()
check on the filepath prior to theopen()
if he wants to ensure he is opening a correctly-spelled existing database rather than accidentally creating a blank new one.... -
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'"
-
@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 tobindValue()
.Read QSqlQuery Class for more details.
-
@KroMignon
It is working now there is just a misspelled word QQuantitiy to QQuantity. Thank you sir :) -
Good day!
I got strange spacing whenever I get a question from my database.
Before I paste to the database:
After I executed the query
Sir @mrjj you mentioned earlier that I can make it look more like a code in a text editor. Like so
How is that? -
I got strange spacing whenever I get a question from my database.
Before I paste to the database:
After I executed the query
Are you using "raw" or tabulation spaces to indent your example codes ?
@mrjj has mentioned the QSyntaxHighlighter
-
@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. -
@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
. -
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.