Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] GUI with arguments
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED] GUI with arguments

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 9.1k Views 1 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    There a way Qt Gui receive an application parameters? And how to put predefined parameters in Qt Creator to build the application?

    @qDebug() << application.arguments();@

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

      they are received in the main.cpp file of all Qt projects. What you need is to retrieve the arguments in the "main" and send it to your "mainwindow" class by the constructor or by a public function.

      Please visit my open-source projects at https://github.com/Code-ReaQtor.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        [quote author="l3e0wulf" date="1359012305"]There a way Qt Gui receive an application parameters?[/quote]"Accessing Command Line Arguments":http://qt-project.org/doc/qt-5.0/qtcore/qcoreapplication.html#accessing-command-line-arguments

        [quote author="l3e0wulf" date="1359012305"]And how to put predefined parameters in Qt Creator to build the application?[/quote]"Specifying Run Settings for Desktop Device Types":http://qt-project.org/doc/qtcreator-2.6/creator-run-settings.html#specifying-run-settings-for-desktop-device-types

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          There is no difference for command line arguments between GUI and console application in Qt. They are always available through qApp->arguments().
          In Qt Creator you can define your custom arguments in Project settings.

          -Looks like i was to slow :)-

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Thanks solved!

            mainwindow.h:
            @explicit MainWindow(QStringList, QWidget *parent = 0);@

            mainwindow.cpp:
            @MainWindow::MainWindow(QStringList arguments, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
            {

            ui->setupUi(this);
            
            qDebug() << arguments;
            

            }@

            main.cpp:
            @MainWindow window(a.arguments());@

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              -Please add "[SOLVED]" prefix to the topic subject. Thanks!-

              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
              • Unsolved