
Using Visual Studio Code for Qt Applications - jcelerier
https://www.kdab.com/using-visual-studio-code-for-qt-apps-pt-1/
======
Alir3z4
Thanks for this, I'm sure many would give it a try and will like the idea of
having the possiblity and easier selection when working with their favorite
IDE or editor when working with Qt.

Having said that, I will never leave QtCreator for VS Code, not that is not
good, but QtCreator feels much solid and integrated than any other IDE when
working with Qt/C++ or many C/C++ code bases out there, in matter of fact,
QtCreator is my go to when doing c/c++.

I've tried CLion but I don't think will use that either.

Need to mention is so damn light ?

~~~
Naac
You're not the first person to mention QtCreator for c/c++ projects ( not even
using QT ). Can you elaborate about what you like about QtCreator over other
c/c++ IDEs?

------
tpush
I'd recommend using clangd together with the vscode-clangd extension instead
of VSCode's "official" C/C++ extension. Properly set up with a
compile_commands.json and its pretty much better than any C/C++ IDE I've ever
used.

~~~
satysin
Interesting. I have used VSCode on Mac for C++ but it has been a royal pain in
the ass recently with lldb-mi issues related to Catalina.

If you don't mind sharing I am very interested in your setup.

~~~
tpush
Sure!

I use CMake for all my projects, and passing "-D
CMAKE_EXPORT_COMPILE_COMMANDS=ON" generates the compile_commands.json for
clangd. I create a symlink to it in the main project folder so clangd can find
it.

Clangd embeds clang-format and clang-tidy, so given appropriate configuration
files formatting in VSCode just works with no extra extensions but vscode-
clangd.

For debugging, I use CodeLLDB. Haven't had any problems with it so far,
everything seems to work fine. Debug console works etc.

------
GnarfGnarf
I use Visual Studio 2017 to develop a Qt application on Windows. I use Qt
Creator (QtC) for same app on macOS. I love Qt, am delighted to have converted
from Win32.

Sorry but VS still feels as solid as a tank, Qt Creator is less responsive to
my needs.

\- 'asserts' in QtC bring the debug session to a grinding halt. I can't step
over like I can in VS.

\- Where can I define macros in QtC?

\- In debug mode, QtC is unable to display certain types of variables, way too
often.

\- I have fiddled for days with the .PRO file, read all the StackOveflow
posts, and I still can't suppress reams of pedantic warnings.

\- QtC just gives the impression of a rudimentary attempt at VS, like things
are about to fall apart at any moment. To a programmer accustomed to VS, there
always seems to be something missing, and I don't mean just different keyboard
shortcuts. QtC has a long way to go.

Still, it's better than a text editor and the command line.

~~~
jcelerier
Fun, I have exactly the opposite experience re. VS and Qt Creator - VS
sometimes takes, like 15 minutes to start a debug session on a large project
while QtC can get to work in the same time that it would take gdb to start.
And that's without counting the clang-based code model, all the niceties under
the locator (ctrl-k), etc etc

> Where can I define macros in QtC?

the IDE is imho not the place to do that. Just use CMake and
target_compile_definitions(my_target PRIVATE MY_MACRO=123)

> \- In debug mode, QtC is unable to display certain types of variables, way
> too often.

very strange, but then I mostly use it on Linux with gdb / lldb, maybe the cdb
integration is less good.

> \- I have fiddled for days with the .PRO file, read all the StackOveflow
> posts, and I still can't suppress reams of pedantic warnings

If CONFIG += warn_off in your .pro (switch to cmake !!!) does not work please
file bugs !

~~~
GnarfGnarf
Sorry, I meant keyboard shortcut macros (Ctrl M, R in VS 2017).

~~~
jcelerier
hmm.. this ? [https://doc.qt.io/qtcreator/creator-
macros.html](https://doc.qt.io/qtcreator/creator-macros.html)

------
irishcoffee
Qtcreator is leaps and bounds ahead of vs

~~~
slezyr
Yeah, also the only IDE that can open and index Chromium sources(about 40k
files).

------
jakearmitage
I love Qt Creator, but the lack of tabs drives me nuts. The interface is so
unfamiliar that I just can't use it. I use it to debug, to build interfaces,
to compile, etc... but to code, I just use Sublime/VS Code/Atom/whatever.

~~~
slezyr
That's funny because I prefer "Open Documents" dock in QtCreator to the tabs.
It's hard for me to switch between files because I can just see 7-8 tabs
without scrolling and in the dock I might have 20 files with longer names.

------
xrd
Is anyone here using gitlab with a runner to build QT applications upon
commit? I've got a friend who needs this and he is only using QTCreator but it
seems like building inside a docker container should be possible. I guess I'm
asking: can all the things discussed here be done from command line instead of
inside the editor and if so, how do you determine those commands?

~~~
wwright
I've led adoption on that exact setup at work. You can definitely do it, but I
have nothing but bad things to say about Qmake. It's poorly documented,
inscrutable, and a huge PITA. Switch to any other build system if you can.

That said, automating the builds in GitLab CI was worth it 1000x over.

~~~
irishcoffee
If you’re fighting qmake there is a very good chance you’re fighting the wrong
problem. Is your build a complicated mess? (It shouldn’t be) Do you have a
complicated multi platform mess (it shouldn’t be complicated)

I would be happy to take a look at your build.

~~~
wwright
Off the top of my head:

\- qmake doesn't support true dependencies between subprojects (ie, if I ask
it to build a/b/c, it can't know that a/b/c depends on d/e/f)

\- qmake's support for integrating additional compilers is inscrutable and
again, has terrible issues with parallelism and dependencies

\- the way it is backed by make is prone to incremental build issues

~~~
irishcoffee
For point 1, it can if you want it to. [https://wiki.qt.io/SUBDIRS_-
_handling_dependencies#Defining_...](https://wiki.qt.io/SUBDIRS_-
_handling_dependencies#Defining_Project_Dependencies:_.depends_attributes)

I have qt kits to build for 4 different platforms and 3 different build
toolchains. It was very easy to set up, and flipping between kits either in
creator or in a terminal takes mere seconds.

I have never experienced your 3rd point.

~~~
wwright
That allows you to support _some_ dependency ordering from the top level, but
not internally. It is very coarse, and also suffers from “recursive Makefile”
issues. It’s also less ergonomic: a developer can’t go into a specific sub
folder and build ONLY that sub folder and its dependencies. If you change a
library, it also can't reliably tell you which other binaries are its
dependents. You have to let Make walk the full project tree.

By “additional compilers,” I mean adding additional metacompilers, other
languages, and so on. There is QMAKE_EXTRA_COMPILERS, but I can’t figure out
how to get it to properly integrate with the dependency graph for the life of
me.

Have you ever had to resort to “make distclean” to get a clean compile?

~~~
jcelerier
> It’s also less ergonomic: a developer can’t go into a specific sub folder
> and build ONLY that sub folder and its dependencies

I'm not a fan of qmake but this works just fine with it.

~~~
wwright
The _dependencies_ is the trick.

Given I have this layout:

    
    
        bin/bin.pro # specify bin/bar/ as subfolder
        bin/bar/bar.c
        bin/bar/bah.h
        bin/bar/bar.pro
        lib/lib.pro # specify lib/foo/ as subfolder
        lib/foo/foo.c
        lib/foo/foo.h
        lib/foo/foo.pro
        project.pro # specify bin/ and lib/ as subfolders
    

And I have a fresh checkout, how do I compile "bin/bar" and all of its
dependencies automatically? I want to run ONLY "bin/bar". I don't want to
compile the entire repo. I don't want to have to investigate "bin/bar" and
learn all of its transitive dependencies. I just want to run "bin/bar".

Honest to god, I have wanted this for over a year and it does not seem
possible.

------
AbuAssar
what advantages does vscode add for c++ development over current IDEs and
editors?

~~~
tinybug
It's simple, light weight, a lot of cool extensions. I use vscode for
developing nodejs, python, ffmpeg, Qt, frontend...it's my all in one IDE.

~~~
Yizahi
How exactly it is lightweight when it carries a copy of Chrome browser in the
background? Jut at idle with no files opened it uses 600 Mb of memory. PS: it
is a nice software which I also use extensively, but Electron is an
abomination, Flash of 21 century.

~~~
0x01101
Just opened it up on my machine (2019 Macbook Pro)- 65MB with no files opened.
No idea how you're getting to almost 10x that.

Edit: My bad, apparently I didn't count all processes.

~~~
jasode
10 minutes ago, I downloaded the latest VSCode 1.43 and installed it on a
fresh macOS 10.15.3.

Launching it with no files open, the total private+shared memory adds up to
~300 MB. Screenshot of macOS Activity Monitor:

[https://imgur.com/a/xDdzDRr](https://imgur.com/a/xDdzDRr)

This memory usage is roughly the same on Windows 10 Task Manager:

[https://imgur.com/a/xWkdoN1](https://imgur.com/a/xWkdoN1)

In contrast, the so-called "heavier" classic Visual Studio 2019 v16.5
(devenv.exe) with no files open, Task Manager stats shows it using less than
~200 MB.

I think some folks get the impression VSCode is "lightweight" because the _GUI
/UI_ is lightweight. VSCode is less "busy" looking... less menu options, no
ribbon with icons, less multi-panels of properties, etc. VSCode's GUI looks
more like a bare-bones "text editor" than an IDE.

------
Vysero
Is there a reason I wouldn't just use creator? Does VS offer me something
creator can not?

~~~
jhasse
Tabs

~~~
jcelerier
Qt Creator has vertical tabs ("Opened documents" panel) which is way superior
as soon as you have more than 3 files open. It's also pretty useless since you
can just <ctrl-k> <first few letters> <enter> or <ctrl-tab> to switch

