33

The problem I have, is that most of the C++ books I read spend almost forever on syntax and the basics of the language, e.g. for and loops while, arrays, lists, pointers, etc.

But they never seem to build anything that is simple enough to use for learning, yet practical enough to get you to understand the philosophy and power of the language.

Then I stumbled upon QT which is an amazing library!

But working through the demos they have, it seems like I am now in the reverse dilemma. I feel like the rich man's son driving round in a sports car subsidized by the father. Like I could build fantastic software, but have no clue what's going on under the hood.

As an example of my dilemma take the task of building a simple web browser. In pure C++, I wouldn't even know where to start, yet with the Qt library it can be done within a few lines on code.

I am not complaining about this. I am just wondering how to fill the knowledge void between the basic structure of the language and the high level interface that the Qt framework provides?

8 Answers8

19

The most damage you will be doing to yourself, if you want to put it that way, is that you will not be learning to use the standard C++ data structures, iterators, algorithms and strings at all. Qt has libraries of its own for all those purposes, and you are all but forced to use them instead of standard C++ entities because Qt APIs only accept data structures of its own.

One could argue that learning to use one algorithms library after mastering other is a trivial task. Before going to an interview where the interviewers expect you to master C++, make sure you deal with that triviality beforehand.

otto
  • 1,184
13

Considering that Qt has its own meta-compiler that you have to process your source files with, it's hard to consider Qt code to be "just C++".

But more importantly, the style of C++ that Qt uses and encourages is something that, to the rest of us, was last seen around 1995.

Really, it's an attempt at making C++ as Java-like as at all possible. It misses out on, or discourages, all the amazing things that actually make C++ worth using today. Instead, you're locked into a subset which most of all feels like an inferior Java.

So if the goal is to learn C++, I'd say no, stay away from Qt. Perhaps take a look at Boost instead, if you want to use an established library as a starting point. Boost embodies the practices that are considered good today.

But honestly, if you want to learn the C++ language, then pick up a good textbook, and focus on the language.

Writing a web browser, no matter how you do it, will at best teach you about web browsers. It won't teach you much about the language you're using.

C++ as a language does not have a WebBrowser class built in. If you read the C++ standard, it says nothing about browsers. It doesn't even mention GUI applications.

That's because those things are built on top, provided by libraries such as Qt. C++, like any programming language, is about logic, about how to express that logic. And yes, that means working with arrays and pointers and loops and all those things.

Would you be able to write a web browser using just those built-in tools, given sufficient time? Would you know how to express the program logic involved? If not, then you need to spend more time on loops and pointers, and less calling new QWebKit() and just piggybacking off ready-made libraries.

The "philosophy and power of the language" is in arrays and lists and loops, not in web browsers.

gnat
  • 20,543
  • 29
  • 115
  • 306
jalf
  • 2,192
11

Do you want to know how stepping on the accelerator makes the car go faster, or do you only care that stepping on the accelerator makes the car go faster?

You are seeing the benefit to black box programming, which is a great way to design a system when all the boxes work. Someone has to make the black boxes though and if you want to be that guy/girl then you need to know more about the language than the guy using the box.

There are jobs that are good jobs in each style, so its up to you what you want to program. IMO you would be doing yourself a disservice though if you didn't put forth the effort to peel back some of the abstraction QT is giving you eventually.

Robert Harvey
  • 200,592
Ryathal
  • 13,486
  • 1
  • 36
  • 48
9

Is Learning C++ Through The Qt Framework Really Learning C++

Maybe.

I'd have to see the code you're putting in your event handlers.

Really though, don't be obsessed with how much you "know". We all use windowing frameworks and we're all still learning. Just keep coding/reading new things and you'll continue learning C++. Learning a new windowing framework is a great addition to your skills even if it might not mean you can implement a neural network or a quicksort in C++.

brian
  • 3,569
5

Don't worry; at first most of your code will just use the framework, but after a while you'll have to extend it, even if just a bit. Then you'll have to use more and more of C++.

Also remember that you have the whole source of Qt available, the IDE will happily take you to the definition of any function/method/class you want. The deeper you go, the more C++ you'll see.

Others have mentioned about the difference between Qt C++ and standard C++. These fall in two camps:

  • different library: Qt includes all the usual containers: arrays, lists, sets, hashmaps, etc. They fit together very well and are good implementations, but they're not the STD variety. Still, in recent versions (4.1 and later, I think) they have 'STD-like' APIs in addition to the old variety (and a Java-like API). In the end, the design choices (when to use an array, when to use a hashmap) are the same, so changing to STD for non-Qt projects is not so hard.

  • moc syntax additions: mostly for signal-handling, but also a couple of nicer loop constructions. Lots of people feel this tool means it's not C++ anymore; but IMHO, they feel just like slightly smarter macros. A good loosely-coupled signal handling is a huge advantage of a good framework, and it's notoriously hard to do on a static typed language. In modern C++, it's doable with a heavy dose of templates; but that was far from standard when Qt first got moc. In the end, if you later want to do non-Qt projects, first check if you'll be using any framework and if it has signals. If yes, then most of what you're used to do with Qt will apply, so no 'harm' in learning Qt first.

Javier
  • 9,958
4

Qt is widely used in the commercial world because it provides a full cross platform toolset and development environment, including a good GUI library.

It also fully supports internationalization, including the excellent 'Linguist' tool.

If you plan an academic career then I wouldn't bother with Qt. If, on the other hand, you like C++ and want to learn a marketable skill then Qt is worth learning.

And yes, Qt is C++, and you can mix in the standard and boost libraries to your hearts content if that makes you feel better.

Jim In Texas
  • 1,453
3

It is a bad idea to learn C++ through Qt. First you have to learn the language concepts independant of any framework and that is what c++ books will teach you and they are right. Basically, 'for and loops while, arrays, lists, pointers' are what programming languages are all about. Additional functionalities are provided by frameworks. Once you learn a programming language, you can learn any framework like Qt or MFC that is built using the language, so that applications can be developed quickly. Regarding Qt, once you learn c++, it is an excellent framework which makes you as productive as any Java or .Net developers. Shortly you will be able develop ios and Android apps using Qt.

Jaak
  • 39
2

Well, I think the best way to learn C++ is by using its own syntax ONLY(Standard C++), so you will be able to use the LANGUAGE stuff, and NOT the Qt(or any other frameworks, libraries ...etc).

Why? because as a beginner, when you look at any C++ code mixed with other Non-C++ code(Qt in this case) you will not be able to see what is C++'s things and what is not, rather it will be more complex process.

CVist
  • 47