Unsolved Advice about the application I will be making? (I'm a beginner)
-
Okay, did you mean this string? I already tried it but it didn't work I think it is one liner meaning I can't put two or more line data.
I want store an image to make it look more a real code rather than just a plain text, but if it is not possible thats fine.
-
@dvlpr.bernard
where you have string, if u open drop down, there is not TEXT type ?ahh. that way.
well we can fix that later with a syntax highlighter
https://doc.qt.io/qt-5/qtwidgets-richtext-syntaxhighlighter-example.html
so when we set text texts its formatted with colors. no need to store image of it. -
@mrjj
Uhhmm I see, I need to use Text rather than string.
Thank you, thank you! -
@dvlpr.bernard
string is a way to optimize the db so one can set a fixed size so if all text is within that, its more efficient, however, for your case with 75 questions. just use TEXT type. -
@mrjj
Sir. Just wondering how can I access the string value from other functions? I want to use it in other functions. -
Hi
what string do you mean ?
The Topic column string from the data base ? -
@mrjj Hello, no. I mean the QString ch_topic whenever the user chooses a topic. How I'm going to get the ch_topic in order to use it in other functions?
-
@dvlpr.bernard
Hi
Just store in main window class.
All the data you want to be shared between functions should be part of MainWindow. (in .h)
At least stuff like selected Topic etc. -
@mrjj
Hello, Hmm didn't know why this is happening. What I did wrong?
-
Hi
You say get_ch_topic is of type MainWindow ???
Should it not QString ?
Or do you mean it should be a function to return
the ch_topic ?
In any case, type of MainWindow just seems wrong. -
@mrjj
I don't know. But I want to define a global object so that other functions can use it. But I just don't know where to declare it -
@dvlpr.bernard
Hi
Just like the
QString ch_topic;
Then all member functions have access to it as they are part of the class. -
@mrjj
whenever I use qDebug() <<get_ch_Topic.getTopic() in the same function where ch_topic was define it returns "IF". But when I use qDebug() <<get_ch_Topic.getTopic() in other functions it return "". I don't know why but maybe because the object name was different?
-
Hi
Do NOT make new instances of the main window class like you do
that is just plain wrong.
You are already in an instance. So no need to ever make new ones.
you can simply use the ch_topic variable.
Its already declared in the MainWindow you are using already. -
@mrjj
Sir, that's what I did before but whenever I do that it says -
well
just use the variable directly. no need to use function.
im not sure what get_ch_tipic is as you dont have () so its not function call.However, if you do
QString MyX; ( in .h as you shown)
then anywhere you can just use it like
MyX = "";
or read it.
is just bad syntax.
as you say get_ch_Topic is a object with the function getTopic and its not true.if you gave MainWindow a function called getTopic
then just call it
qDebug() << getTopic();Its important to understand that all you add to MainWindow class ( in .h)
can be access from any functio that also a memebr .
that is
MainWindow::SomeFunction() {
any variable from .h you can use here. no special syntax. just use it.
} -
Thank you sir. I just don't know but still it doesn't work it just return "" not "WHILE". :(
-
@dvlpr.bernard
hi
check code where you set it.
Maybe you create other instance you set it on ? -
@mrjj
Hello sir,
Where should I declare a global instance / object in my 3 files.
mainwindow.h, main.cpp, or mainwindow.cpp?
Ang how whenever I declare one because whenever I declare one e.g. (MainWindow get_ch_Topic;) it display an error "no previous extern declaration for non-static variable" -
@dvlpr.bernard said in Advice about the application I will be making? (I'm a beginner):
Where should I declare a global instance / object in my 3 files.
Nowhere! Avoid global variables especially if those are derived from QObject!
Why do you need global variables at all?