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. [SOLVED] How to use main args
QtWS25 Last Chance

[SOLVED] How to use main args

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.3k 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.
  • R Offline
    R Offline
    roseicollis
    wrote on last edited by
    #1

    Hi,

    I'm making a Qt Gui application so the main its like:

    @
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv); //Maybe I can do something with that?
    MainWindow w;
    w.show();

    return a.exec();
    

    }
    @

    I need to use those arguments (argc, argv[]) in the mainwindow. So my question is: How can I use them there? The only solution I can think of is to create a new class which receives them, put them in global variables and then inherite mainwindow from the new class but I don't really like it and I suposse there is an easer way to do it.
    I've been searching the QApplication behaviour but nothing found

    Thanks!

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

      Hi,

      You are looking for "this":http://doc.qt.io/qt-5/qcoreapplication.html#accessing-command-line-arguments part of the documentation.

      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
      0
      • R Offline
        R Offline
        roseicollis
        wrote on last edited by
        #3

        Yeah! That's it!

        @QStringList ArgsList = QApplication::arguments(); @

        Next time I'll say: Hi Sgaist I think XDDD Thank you for all :D

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Francknos
          wrote on last edited by
          #4

          [quote author="roseicollis" date="1419334108"]Hi,

          I'm making a Qt Gui application so the main its like:

          @
          int main(int argc, char *argv[])
          {
          QApplication a(argc, argv); //Maybe I can do something with that?
          MainWindow w;
          w.show();

          return a.exec();
          

          }
          @

          I need to use those arguments (argc, argv[]) in the mainwindow. So my question is: How can I use them there? The only solution I can think of is to create a new class which receives them, put them in global variables and then inherite mainwindow from the new class but I don't really like it and I suposse there is an easer way to do it.
          I've been searching the QApplication behaviour but nothing found

          Thanks![/quote]

          You can do this

          @
          int main(int argc, char *argv[])
          {
          QApplication a(argc, argv); //Maybe I can do something with that?
          MainWindow w(argc, argv); // And use it in your constructor of MainW
          w.show();

          return a.exec();
          

          }
          @

          1 Reply Last reply
          0
          • R Offline
            R Offline
            roseicollis
            wrote on last edited by
            #5

            Hi Francknos,

            Sorry but if I do that ( I already tried it before psoting here), you can't use them in mainwindow as int a = argc; or something like that.

            Anyway as the title says, it has been already solved so thanks :)

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Francknos
              wrote on last edited by
              #6

              Ok no problem.
              But why you want modify the argc, argv in your app ?

              1 Reply Last reply
              0
              • R Offline
                R Offline
                roseicollis
                wrote on last edited by
                #7

                I didnt want to modify them, just to use them :)

                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