-2

I'm trying to learn some C++ by studying the source code of VLC media player. I've noticed that many files have #include but I can't find where QMenu is included from, even after searching through the source code using grep. Surely the class declaration must be included in the source code somewhere?

Urthona26
  • 109
  • 5
  • Instead of trying to search the source code, read the documentation, e.g. https://doc.qt.io/qt-5/qmenu.html – user17732522 Mar 26 '22 at 00:03
  • 2
    VLC Media Player is a highly advanced, very technical, application that must be using not just many advanced, technical C++ techniques, but also advanced video and audio processing algorithms as well, that require full, in-depth domain knowledge of audio-visual processing to fully understand. Attempting to learn C++ from VLC's source code is like attempting to understand Newton's laws of motion by inspecting the innards of an Airbus A380. – Sam Varshavchik Mar 26 '22 at 00:07
  • @user17732522 I've been o this page already and it doesn't answer my question. – Urthona26 Mar 26 '22 at 00:14
  • @Urthona26 Maybe I am misunderstanding the question then. My impression was that you want to understand VLC's code and for this need to understand the behavior of QMenu, so you were looking for its source code. But for complex libraries like Qt it is better to look at the documentation than the code to determine the defined behaviors. – user17732522 Mar 26 '22 at 00:16
  • @Sam Varshavchik I've tried learning javascript before. The problem I had was that I read a book on javascript and learned about basic things like loops and variable types but after that I still could barely write any code because of the seemingly thousands of libraries and built in functions. It would seem that rather than trying to memorise all these functions without context it would be easier to learn by them by seeing them in action in an actual program. How else would you suggest I learn C? – Urthona26 Mar 26 '22 at 00:21
  • @user17732522 You are right. I do want to understand QMenu's behaviour. But I'm also confused about why I can't find it in the source code I'm looking at. If it isn't in the source code for some reason and is being imported from somewhere else, this is something important I should know about. – Urthona26 Mar 26 '22 at 00:23
  • Dumb question: did you actually downloaded Qt on your machine? `QMenu` source isn't within VLC, but within Qt... And honestly, without a STRONG level in both Qt and C++, you won't understand anything by reading `QMenu` source code... – Wisblade Mar 26 '22 at 00:27
  • @Urthona26 You can just look at it in the Qt source code, e.g. for the current development branch [here](https://github.com/qt/qtbase/blob/dev/src/widgets/widgets/qmenu.h#L61). If you installed the Qt development packages on your machine, this file should also be somewhere on your system. For example it is at `/usr/include/x86_64-linux-gnu/qt5/QtWidgets/qmenu.h` on my Linux system. (Although I don't actually know whether VLC uses Qt5 or a previous version.) – user17732522 Mar 26 '22 at 00:29
  • @user17732522 Thank you. I think that answers my question. So does that mean if Qt isn't installed on my machine already, VLC won't work? – Urthona26 Mar 26 '22 at 00:36
  • Since everyone here is telling me that trying to learn C by studying the VLC source code is smooth of brain, I'll try some other approach. But I'm not happy about it. – Urthona26 Mar 26 '22 at 00:37
  • Javascript is not C++. They are worlds apart. Javascript is an interpreted (theoretically, ignoring JIT for the moment), loosely-typed language. C++ is a strongly-typed compiled language. The full technical specifications for the core of C++ runs to about 2000 pages of terse text. In Javascript there are no equivalent to C++'s multiple inheritance, containers, iterators, algorithms, templates, concepts, or constraints. C++ is just too complicated and just cannot be learned simply by reading random code. – Sam Varshavchik Mar 26 '22 at 00:37
  • @Urthona26 If you mean whether the compiled binary will work, that depends on whether the binary statically links the Qt library or ships it with the binary. If it does neither, then yes, it won't run. If you mean whether you can compile it, then yes you will need to have the Qt libraries and headers available somehow. – user17732522 Mar 26 '22 at 00:38
  • Also just to help you not get lost. C and C++ are different, although related, languages. Although a lot of valid C is also valid C++, the coding styles and methods are completely different between the two. So decide which one you want to learn. Both languages are known for relying heavily on specification of behavior in standard documents. – user17732522 Mar 26 '22 at 00:52
  • In contrast to languages like JavaScript, there will usually be no warning if you don't follow e.g. the specifications of a library function. Instead the behavior of the resulting program will just be completely undefined (may seem to work sometimes and crash another time or give wrong output, etc.). (Although weak typing probably causes similar issues) Therefore it is important to read, understand and remember the specified requirements and behaviors. Introductory book recommendations for C++ can be found [here](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – user17732522 Mar 26 '22 at 00:52
  • 2
    That said, I don't think there is anything wrong with studying the code of whatever project you like. You just need to accept that you won't understand it all and it shouldn't be the _only_ part of the learning process. – user17732522 Mar 26 '22 at 00:57

1 Answers1

0

You can find excellent code browser on Woboq https://code.woboq.org/qt6/ and specifically QMenu class definition is here https://code.woboq.org/qt6/qtbase/src/widgets/widgets/qmenu.h.html

Or you can download Qt source code (install it via Qt Maintenance Tool) and browse it yourself locally.

PS: As other said in the comments, learning the very basics of C++ by reading VLC source code is not a good idea. And also Qt code is not a vanilla C++. If you want to learn C++ I would recommend for example The Cherno's channel on youtube. IMO, it is the best explanation of C++ basics https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb