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. Overview of structure question
Qt 6.11 is out! See what's new in the release blog

Overview of structure question

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 836 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.
  • U Offline
    U Offline
    Uberlinc
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @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
      1 Reply Last reply
      0
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by Kent-Dorfman
        #3

        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.

        The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

        U 1 Reply Last reply
        4
        • Kent-DorfmanK Kent-Dorfman

          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.

          U Offline
          U Offline
          Uberlinc
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            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
            2
            • U Offline
              U Offline
              Uberlinc
              wrote on last edited by
              #6

              Thank you.

              I'll give that a try.

              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