Solved Overview of structure question
-
Hi,
So, I'm sufficiently proficient in C++ to continue, and I'm trying my hand at Qt.
So, I'm trying to practice anything and everything I can in C++ but putting it into a Qt windowed application.The thing I don't understand is where the plain ol' C++ code fits into the Qt picture.
For example, I have a basic, working Qt application with a QTextEdit to print out rows of text.
Now, I want to open a file, import text from it, put it into a vector and then do some parsing of the content and then print the results back out of the QTextEdit window.
I can do one in pure C++ and one in Qt but not sure how to tie them together.
Where would I put the file open/import/loading/parsing code into this big picture?
Is it made a part of MainWIndow or do I make a somethingelse.h and somethingelse.cpp and somehow tie it in?
If so, how?If someone can point me to a tutorial on this, I'd be greatly appreciative.
Thanks.
-
@Uberlinc said in Overview of structure question:
Is it made a part of MainWIndow or do I make a somethingelse.h and somethingelse.cpp and somehow tie it in?
If so, how?A lot depends on how your existing code is structured, but it could be as simple as:
- Put some code in your GUI to ask the user for a file name and call your pre-existing C++ code with the file name to open, parse etc.
- When the parsing is done call a function in your pre-existing C++ code to return the result to put in your text edit. You might need to do format conversions e.g. between QString and std::string
To make your existing code available in your program you can:
- Build it in: add somethingelse.h to HEADERS and somethingelse.cpp to SOURCES
- Build it as a shared library and link it in: add the necessary stuff to LIBS e.g unix:LIBS += -lsomethingelse
-
GUI programming requires adopting a different mindset (event driven programming). You don't have a program that starts at the top and runs through consecutive instructions. instead you have a series of functions/call-backs that you fill in the detail, and they are implicitly called by a hidden event processing loop that is provided by the framework. Regular sequential C++ programming doesn't prepare people for that. So it's not as simple as designing a sequential series of instructions and branches to accomplish your objective.
Don't skip steps! Read, compile, run, and comprehend the examples before expecting to just start programming for Qt.
Don't do anything that will "block" the event processing loop. All actions in the prgram should be triggered by some event/signal. If an action is long running then it should be encapsulated in a separate thread that signals the main event loop upon completion.
-
@Kent-Dorfman said in Overview of structure question:
GUI programming requires adopting a different mindset (event driven programming).
Okay, so if you might need something to run at some point in the program, regardless of user action, where would you put it?
Don't skip steps! Read, compile, run, and comprehend the examples before expecting to just start programming for Qt.
Which examples are you referring to? What tutorials would you recommend as a comprehensive beginner's guide to Qt?
Many thanks.
-
Hi,
The most simple is to skim through Qt's own documentation. It provides quite a lot of examples covering a relatively large base of standard use cases.
-
Thank you.
I'll give that a try.