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. GUI app print to console
Forum Updated to NodeBB v4.3 + New Features

GUI app print to console

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 2.3k 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
    #2

    Hi
    yes, its possible.
    Doc has sample.
    http://doc.qt.io/qt-5/qapplication.html#details
    The trick is to use QCoreApplication instead of QApplication and
    a parameter telling when to run non gui.

    But for this to work as intended, you must design your app
    so any data it needs or function do not
    live in mainwindow or other widgets.
    Then your app can work in both modes.

    1 Reply Last reply
    4
    • T Offline
      T Offline
      t0msk
      wrote on last edited by
      #3

      Thank you very much, sorry for late reply, just one more question this is only one way?

      Or is possible that program will detect if it is run from command line or just by arguments like:

      "-no-gui"
      

      ?

      Student who loves C/C++

      mrjjM 1 Reply Last reply
      0
      • T t0msk

        Thank you very much, sorry for late reply, just one more question this is only one way?

        Or is possible that program will detect if it is run from command line or just by arguments like:

        "-no-gui"
        

        ?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @t0msk
        Well it uses the parameter to know, so it needs some flag in some form or another.
        I have not seen other methods, but some could exists involving navtive api calls
        to find out if run from a shell or via other means of activation.

        1 Reply Last reply
        1
        • T Offline
          T Offline
          t0msk
          wrote on last edited by
          #5

          Thank you and does have Qt access to some of these API calls? Or it must be done in pure C++?

          Student who loves C/C++

          mrjjM 1 Reply Last reply
          0
          • T t0msk

            Thank you and does have Qt access to some of these API calls? Or it must be done in pure C++?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @t0msk
            Hi
            Qt is pure c++. :)
            But there would not be a Qt class for it.
            You would use native windows / linux apis
            something like shown here
            https://stackoverflow.com/questions/9009333/how-to-check-if-the-program-is-run-from-a-console

            1 Reply Last reply
            0
            • T Offline
              T Offline
              t0msk
              wrote on last edited by
              #7

              Thank you :) I consider Qt as framework for C++ :) By pure C++ I meant code without Qt classes :)

              Student who loves C/C++

              mrjjM 1 Reply Last reply
              0
              • T t0msk

                Thank you :) I consider Qt as framework for C++ :) By pure C++ I meant code without Qt classes :)

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #8

                @t0msk
                hi
                ok, well it would be ok fine to do in a Qt app.
                but its not crossplatform.

                T 1 Reply Last reply
                0
                • mrjjM mrjj

                  @t0msk
                  hi
                  ok, well it would be ok fine to do in a Qt app.
                  but its not crossplatform.

                  T Offline
                  T Offline
                  t0msk
                  wrote on last edited by t0msk
                  #9

                  @mrjj I think it could be cross platform, if I added support for Linux, Windows and Mac like:

                  #ifdef __linux__ 
                      //linux code goes here
                  #elif _WIN32
                      //windows code goes here
                  #else
                  
                  #endif
                  

                  Student who loves C/C++

                  mrjjM 1 Reply Last reply
                  1
                  • T t0msk

                    @mrjj I think it could be cross platform, if I added support for Linux, Windows and Mac like:

                    #ifdef __linux__ 
                        //linux code goes here
                    #elif _WIN32
                        //windows code goes here
                    #else
                    
                    #endif
                    
                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @t0msk
                    hi
                    Yes, that's the normal way to have different code for
                    each platform since same calls wont work.
                    So if you wrap it up in a nice class, and add code for each platform
                    it will be crossplatform :)

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

                      Hi,

                      Qt already provides macros for the OS it supports. See here.

                      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
                      4

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved