Linux qt creator консоль

Using Command Line Options

You can start Qt Creator and specify some options from the command line. For example, you can open a file to any line and column.

To specify command line options, enter the following command in the Qt Creator installation or build directory:

qtcreator [option] [filename[:line_number[:column_number]]]

Note: You can use either a colon (:) or a plus sign (+) as a separator between the filename and line number and the line number and the column number. You can also use a space between the separator and the line number.

For example, on Windows:

  • C:\qtcreator\bin>qtcreator -help
  • C:\qtcreator\bin>qtcreator C:\TextFinder\textfinder.cpp:100:2
  • C:\qtcreator\bin>qtcreator C:\TextFinder\textfinder.cpp +100+2
  • Qt\ Creator.app/Contents/MacOS/Qt\ Creator -help

To open a project that is located in a particular folder, you can pass on the folder name as a command line argument. Qt Creator looks for a session that matches the folder name and loads it. Or it looks for a project file in the folder and opens it. For example:

Note: To run a self-built Qt Creator from the command line on Windows, make sure that the Qt installation directory is included in the PATH environment variable. You can enter the following command on the command line to add Qt to the path:

The following table summarizes the available options:

Option Description
-help Display help on command line options.
-version Display Qt Creator version.
-client Attempt to connect to an already running instance of Qt Creator.
-pid Attempt to connect to an already running instance of Qt Creator with the specified process ID.
-block Open files in editors in a running Qt Creator instance and block the command line until the first editor is closed.
-nocrashcheck Disable the startup check for a previously crashed Qt Creator instance.
-load

Enable the specified plugin and all plugins that it depends on. You can combine -load and -noload options and specify both options multiple times to enable and disable several plugins. The actions are executed in the specified order. -load all Enable all plugins. -noload

Disable the specified plugin and all plugins that depend on it. -noload all Disable all plugins. -profile Output profiling data about plugin startup and shutdown. -pluginpath

Add a path where Qt Creator looks for plugins. To specify several paths, add the -pluginpath option for each path. -settingspath

Override the default path where user settings are stored. -installsettingspath

Override the default path from where user-independent settings are read (for example written by the installer). -temporarycleansettings, -tcs Use clean settings for debug or testing reasons. The settings will be deleted when Qt Creator exits. -test

[,testfunction[:testdata]] . For Qt Creator plugin developers: run the plugin’s tests using a separate settings path by default. -test all For Qt Creator plugin developers: run tests from all plugins. -notest

For Qt Creator plugin developers: exclude all of the plugin’s tests from the test run. -scenario For Qt Creator plugin developers: run the specified scenario. -color Core plugin: override the selected UI color. -presentationMode Core plugin: display keyboard shortcuts as popups when you press them. Mostly useful when presenting Qt Creator to someone else. -theme Core plugin: apply a dark color theme to Qt Creator, without using stylesheets. -notour Welcome plugin: skip the UI tour on startup. -debug

Debugger plugin: attach to the process with the given process ID. -debug [,kit= ] Debugger plugin: launch and debug the executable with the name executable . A kit can be specified by ID or name to point to non-default debuggers and sysroots. -debug [executable,]core= [,kit= ] Debugger plugin: load the core file named corefile . The parameter executable specifies the executable that produced the core file. If this parameter is omitted, Qt Creator will attempt to reconstruct it from the core file itself. This will fail for paths with more than about 80 characters. In such cases the executable parameter is mandatory. A kit can be specified by ID or name to point to non-default debuggers and sysroots. -debug ,server= [,kit= ] Debugger plugin: attach to a debug server running on the port port on the server server . The parameter executable specifies a local copy of the executable the remote debug server is manipulating. A kit can be specified by ID or name to point to non-default debuggers and sysroots. -wincrashevent Debugger plugin: attach to crashed processes by using the specified event handle and process ID. -git-show Git plugin: show the specified commit hash. -customwizard-verbose ProjectExplorer plugin: display additional information when loading custom wizards. For more information about custom wizards, see Adding New Custom Wizards -ensure-kit-for-binary

ProjectExplorer plugin: create a kit with a toolchain corresponding to the given binary’s architecture. -lastsession ProjectExplorer plugin: load the last session when Qt Creator starts. Open the projects and files that were open when you last exited Qt Creator. For more information about managing sessions, see Managing Sessions. ProjectExplorer plugin: load the given session when Qt Creator starts. Open the projects and files that were open when you last exited Qt Creator. For more information about managing sessions, see Managing Sessions.

Using Custom Styles

Qt Creator is a Qt application, and therefore, it accepts the command line options that all Qt applications accept. For example, you can use the -style and -stylesheet options to apply custom styles and stylesheets. The styling is only applied during the current session.

Exercise caution when applying styles, as overriding the existing styling may make some items difficult to see. Also, setting a stylesheet may affect the text editor color scheme and the styling of the integrated Qt Designer.

You can also switch to a dark theme to customize the appearance of widgets, colors, and icons without using stylesheets.

В© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

Источник

Getting Started on the Commandline

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

Introduction

Welcome to C++! This guide will show you how to get started with C++ application development with Qt. Before you continue you may want to start downloading the Qt SDK from here. Choose the Community version if unsure. The source code examples in this guide are entirely LGPL compatible. On Linux you can also just install libqt4-dev and g++ using your favorite package manager.

«Hello, world!» console application

Let’s begin with a simple C++ program. Open a text editor and enter the following source code. Keep care to type it exactly like shown in the following example. Like most programming languages C++ is case-sensitive.

Create a directory «hello» and save the source code into a file hello.cpp residing in this directory.

The download of the Qt SDK or package install should be finished by now.

Open a shell and inspect which version of Qt you have installed: enter «qmake -v». If qmake can’t be found you have to add its installation path to your environment variable. Search for it in the SDK installation directory.

Now enter the «hello» directory and type: «qmake -project». This will create an qmake project file. Thereafter run just «qmake» without arguments. this will create a «Makefile» which contains the rules to build your application. Then run «make» (called nmake or gmake on some platforms), which will build your app according to the rules layed out in the «Makefile». Finally you can run the app «./hello».

So, on a bash command prompt you would enter:

«Hello, world!» desktop application

Simply replace the source code in hello.cpp by:

Add the following lines to the .pro file after the include path:

Run «qmake» and then «make» again. If you launch the application should see a small window saying «Hello, world!».

Источник

How to write a nice console application with Qt and Qt Creator.


Abstract:

We give the project a name and a directory.

We select the modules we need for the application. If we do now add modules now, we can add them to the project later.

Qt creater created two files for us. The first one is consoleapp.pro. The contents is the following:

This is a Qt project file and we do not have to change it now. The second one is the main.cpp file. As you might expect, this program is not doing anything. I even have bad news for you, if you run it, it does not end!

The output of this application is not what you expect. You will have to run the application to know exactly what I mean. The first two lines of output will be shown immediately. The one you expect to be the first will be the last and it will be shown after 5 seconds. The last funny thing is the qDebug output. It has an extra newline after it! Did you expect this output?

  1. flush the buffer explicitly
  2. use endl instead of the backslash n at the end of the string

Using endl will flush the buffer inplicitly. In this case, it is the prefered way. You could have used qout.flush() to explicitly flush to buffer to. The qDebug has a kind of build in endl and does not need to have an extra one. I took it out! Now this is what the code looks like:

The output you expected to get in the first place.

You will see the output at once, than the application waits till the 5 seconds are over and quits. So far so good. To write some nice console application we need to do something. Now we will add some sourcecode which can be filled to do something usefull. When the task is done, we will end the application. For demonstration purposes, we still leave the 5 seconds trigger at the end. We will need it! The first thing to do is to add a new class. This can be done by right clicking on the project and selecting add.

Now I changed the generated class a bit so it can be used. The ctodo.h file has been changed to:

I also changed the ctodo.cpp file so it can show something on the screen.

If you get error messages concerning «vtables not found» you need to run qmake. This can be done by selecting it from the menu or by involing a complete build from the menu. If you run the programm you will see that the program will not quit with your signal. Instead it will wait and end after 5 seconds. This again is not what I would expect. If you would not have this 5 seconds signal, it will run forever! The program will output is shown below.

If you run the application now, you will notice that the 5 seconds timer is not needed anymore. The program will stop before it can be triggered. If you fill this template application with life, do not forget to take the 5 seconds timer out just in case your application runs longer than 5 seconds. This timer (QTimer::singleShot()) was only needed for explaining the application so we did not have to kill it all the time during experimenting.

Источник

qtcreator проблемы с консолью

Создал консольное приложение на C++, первый запуск — все нормально, открывается консоль и есть вывод. Второй раз и открывается просто пустая консоль, которая ни на что не реагирует (символы туда вводить можно, но это бесполезно). Пробовал и с konsole и с xterm. Версия qtcreator — 2.8.1
Дистрибутив: gentoo
DE: kde 4.12
qt 4.8.5
Как это побороть?

Если запускать отдельно из консоли то бинарь работает нормально.

А во встроенной консоли QtCreator возникает такая же проблема? P.S.: Чтобы переключиться на встроенную консоль — убрать галку «Run in terminal» (Projects -> Build & Run -> Desktop [Run] -> Run in terminal)

Нет, в нем все в порядке, но не работает ввод (cin)

Неужели никто не сталкивался с такой проблемой? Или просто никто не программирует на линуксе?

Я никогда не додумывался отлаживать программы с консольным вводом через встроенный терминал. Хотя именно Qt Creator-ом только и пользуюсь.

Советую осилить файлы, и делать ввод-вывод в них.

Но это все равно костыли и мне удобнее отдельный терминал, а не встроенный. И у тебя в qtcreator все работает?

Не, я нигде такое не использую, ни встроенный ни внутренний.

Но чтобы внешний терминал не работал — удивлен. Ни разу не замечал чтобы это было проблемой. При случае попробую — отпишусь.

Такое встречалось и у других, в убунте заметил похожее, но там была проблема с ptrace, у других решалась полным прописыванием пути до терминала (например /ust/sbin/konsole -e), но мне что-то не помогло.

У некоторых программ, например у Double Commander, есть проблема что если повторно вызываешь терминал (второе окно) — он ведет себя иначе, хотя казалось бы — да хоть сто штук и чо.

в том то и дело, что до этого терминал закрываю. При этом кажется не завершается процесс выполненной программы. Хотя такого не может быть, ведь нечему долго выполняться в «хеллоу ворлде»

Нет, в нем все в порядке, но не работает ввод (cin)

У меня тоже не работает (и скорее всего никогда не работало). Меня больше интересовал факт работы вывода.

Неужели никто не сталкивался с такой проблемой? Или просто никто не программирует на линуксе?

Я помню у меня были проблемы с консолью, но с такой проблемой как у тебя не сталкивался.

в том то и дело, что до этого терминал закрываю. При этом кажется не завершается процесс выполненной программы. Хотя такого не может быть, ведь нечему долго выполняться в «хеллоу ворлде»

Зачем гадать, если можно проверить это:

Но я думаю проблема скорее всего в самой среде.. Вижу несколько вариантов: 1) Костыльный: можно в настройках проекта сделать свою опцию запуска приложения. 2) Попробовать установить более новую среду разработки с сайта. 3) Искать в bugtracker’e ошибку и возможное решение.

Источник

Читайте также:  Compile driver linux kernel
КомпСовет