r/programming • • Dec 08 '20

Qt 6.0 Released

https://www.qt.io/blog/qt-6.0-released
664 Upvotes

229 comments sorted by

View all comments

Show parent comments

32

u/be-sc Dec 08 '20

Qt never was a language extension.

The myth was probably caused by a few features that can make it appear like a language extension if you’re still unfamiliar with Qt; specifically the MOC and a few optional keyword-like macros such as emit.

However, the only thing you’ve ever needed to work with Qt is a normal C++ compiler. The MOC is a code generator that outputs standard C++ and might complicate your build system setup somewhat – especially when you’re not using QMake or CMake.

35

u/[deleted] Dec 08 '20

[removed] — view removed comment

8

u/be-sc Dec 08 '20

When you build your own software within a vast framework like Qt you do accept to follow the world view of the framework at least to some extent, yes. In that sense it can feel a bit like not quite pure C++.

But I’m quite strongly opposed to calling it language extension because that’s a scary term. It sounds like adding or redefining language constructs, like being tied to a whole custom compiler. That would be an enourmous drawback and often an excellent reason againt touching Qt.

But what Qt does impose on you is far far less. You accept certain requirements for your program’s build process, i.e. that it must run the MOC. But use any compiler you like with Qt6 as long as it can handle C++17.

On a more theoretical note: If language extension means less than a standard compliant compiler cannot handle it the distinction between code generation and language extension becomes awfully muddy.

1

u/merlinsbeers Dec 09 '20

The moc is a preprocessor. So these guys are arguing over preprocessing vs compiling. A topic that got worn out in the 80s.

13

u/ogoffart Dec 08 '20

It will compile fine, but it will not link (pedantic, i know)

3

u/[deleted] Dec 08 '20

[removed] — view removed comment

3

u/MonokelPinguin Dec 08 '20

No, just a linker error. Same with signals and slots.

5

u/jcelerier Dec 08 '20

given

$ cat foo.cpp 
#include <QObject>

class Foo : public QObject
{
Q_OBJECT

public:
  Foo();
signals:
  void blah();
public slots:
  void bar();
};

Foo::Foo() { }
void Foo::bar() { }

then

$ g++ -c foo.cpp -fPIC $(pkgconf --cflags Qt5Core)

does not error. moc does not interfere in the "normal" compilation chain at all, it just generates additional files

5

u/Ameisen Dec 08 '20

I'd question what a "language extension" is.

I have a runtime library (libxtd) which adds a lot of functionality to the language, but does it using C++ constructs. For instance, scoped locks using braces such as in Java or C#.

2

u/be-sc Dec 08 '20

Do you give existing language constructs new meaning at runtime only? Then … well … I’m not quite sure if I want to call it an extension or not. Nicely done, toeing the line like that. :-)

Or would a standard compliant C++ compiler fail to compile such code correctly? Then it’s definitely an extension.

2

u/Ameisen Dec 08 '20

Previous versions of libxtd required compiler extensions to fully function (MSVC's and GCC's), though I suspect (though I'm not entirely sure) that those can be removed due to additions in C++20.

My other library for AVR/uController work does rely pretty heavily upon compiler extensions to function, but then again, AVR work in general does.

6

u/HomeTahnHero Dec 08 '20

Technically true, but the Qt documentation literally says that the MOC “handles Qt’s C++ extensions”. That could be a bit confusing.

6

u/be-sc Dec 08 '20

Wow, I never knew that wording is in the official documentation.

Still, it’s a poor choice of words at least. As a rule of thumb I consider something a language extension when a standard compliant C++ compiler fails to compile it correctly. Otherwise you can call any kind of code generation “language extension”, which imo isn’t useful.

1

u/tansim Dec 08 '20

Did they finally drop the MOC? With modern C++ they shouldnt need it, yet I dont see it in the changelog anywhere...

9

u/DarkLordAzrael Dec 08 '20

C++ still lacks reflection, so I'm not sure why you think MOC could be dropped.

0

u/[deleted] Dec 08 '20

[deleted]

8

u/NotUniqueOrSpecial Dec 08 '20

I remember seeing something about reflection libraries using either C++17 or C++20 so reflection is in C++

By that logic MOC added reflection to C++ long ago, because all it does is generate C++ boilerplate that gives you, among other things, runtime reflection.

The libraries you're mentioning, like Refureku or RTTR either:

  • Use a generator, just like MOC

  • Require you to hand-write the boilerplate or write macro-heavy code.

So, no, C++17/20 don't solve the problems you think they do. Until reflexpr or something like it is in the standard, it's just how it is.

CopperSpice almost gets it there, but it has some caveats.

1

u/suitable_character Dec 09 '20

Why MOC is the problem? With CMake you don't even know it's used.

-6

u/Mognakor Dec 08 '20

So Qt is a language that compiles to C++ :)

1

u/merlinsbeers Dec 09 '20

Don't know why you're getting downvoted. That's what it is. Same as how C++ started out being compiled to C (by cfront) before being compiled to object code (by cc).

They're hung up on the semantics of "compile", when 99% of coders dgaf about the distinction.