Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to share command line argument?
Forum Updated to NodeBB v4.3 + New Features

How to share command line argument?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 479 Views
  • 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.
  • K Offline
    K Offline
    Knj.Tkm
    wrote on last edited by
    #1

    Hi.
    I've only been using C++ for a short time.
    How can I use the command line arguments in another cpp file?
    I thought of a way to use a global variable, but I hear that global variables should be avoided.
    Is there any other way than global variables?

    jsulmJ 1 Reply Last reply
    0
    • K Knj.Tkm

      Hi.
      I've only been using C++ for a short time.
      How can I use the command line arguments in another cpp file?
      I thought of a way to use a global variable, but I hear that global variables should be avoided.
      Is there any other way than global variables?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Knj-Tkm https://doc.qt.io/qt-5/qcoreapplication.html#arguments
      https://doc.qt.io/qt-5/qapplication.html#qApp

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • K Offline
        K Offline
        Knj.Tkm
        wrote on last edited by Knj.Tkm
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • jsulmJ jsulm

          @Knj-Tkm https://doc.qt.io/qt-5/qcoreapplication.html#arguments
          https://doc.qt.io/qt-5/qapplication.html#qApp

          K Offline
          K Offline
          Knj.Tkm
          wrote on last edited by
          #4

          @jsulm
          Does it matter if I use it outside of the main function?

          jsulmJ 1 Reply Last reply
          0
          • K Knj.Tkm

            @jsulm
            Does it matter if I use it outside of the main function?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Knj-Tkm said in How to share command line argument?:

            Does it matter if I use it outside of the main function?

            No, why should it?
            It will work after app (QApplication) instance was created:

            QApplication a(argc, argv);
            

            qApp is a macro which can be used everywhere in your application.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            K 1 Reply Last reply
            1
            • jsulmJ jsulm

              @Knj-Tkm said in How to share command line argument?:

              Does it matter if I use it outside of the main function?

              No, why should it?
              It will work after app (QApplication) instance was created:

              QApplication a(argc, argv);
              

              qApp is a macro which can be used everywhere in your application.

              K Offline
              K Offline
              Knj.Tkm
              wrote on last edited by
              #6

              @jsulm
              OK, Thanks!

              1 Reply Last reply
              1

              • Login

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