[画像:Better_Software_Header_Mobile] [画像:Better_Software_Header_Web]

Find what you need - explore our website and developer resources

KDAB contributions to Qt 5.0 (part 1)

Yesterday Qt 5.0.0 was released. It is the culmination of huge amounts of work since the announcement of and start of Qt 5's development. This is the first major release of Qt since the launch of open governance in Autumn 2011, when it became much easier for external individuals and companies to contribute to Qt in terms of code submissions, code reviews, design, and maintenance.

As KDAB benefits from a successful Qt, we have made investments to contribute to the long-term health of the frameworks. There are over 1100 commits from KDAB in the qtbase git repository alone, and many others in other Qt repositories. Excluding individual contributors, we have consistently been the next biggest contributor, second only to the owners of Qt (Nokia/Digia). We have been fixing bugs, implementing wishes from the JIRA tracker, designing writing and testing new features, implementing platform support, reviewing other contributors' code and participating in discussions around the project.

A new blog series here will detail some of the interesting features of Qt 5.0 which were contributed by KDAB.

QEventLoopLocker

One of the early complete new features contributed by KDAB to Qt 5 was the QEventLoopLocker. This is a class whose need first appeared in KDE, and it relates to the quitOnLastWindowClosed concept in Qt. For KDE applications, there was a desire to quit applications when the last window was closed, but there was also a need to finish some operation before quitting the application. For example, the email with the large attachment is not fully sent yet, or we're still uploading a large file to an FTP site somewhere. As these operations typically have separate, out-of-process UI, it is ok to not show any window until the job is finished.

That concept was generalized to be able to quit not just the application, but any event loop or any thread, using the new QEventLoopLocker RAII class. This will make implementation of job-queues much easier in Qt 5. For maintenance, the quitOnLastWindowClosed feature in Qt is implemented using the same implementation details as the QEventLoopLocker.

Improved MetaType features

The QMetaType system has seen some large improvements in Qt 5 contributed by KDAB. Some of the improvements were explained at Qt Developer Days in Berlin.

Declaring and using metatypes is now much more convenient in many cases. For example, if you wrote a MyObject type inheriting QObject, or MyWidget type inheriting QWidget in Qt 4, and you wished to put an instance of it into a QVariant, you would need to first use

Q_DECLARE_METATYPE(MyObject*)

AltStyle によって変換されたページ (->オリジナル) /

somewhere in your code. That would allow you to use

QVariant var = QVariant::fromValue(myObjectInstance);

In Qt 5, the Q_DECLARE_METATYPE use is no longer needed if your type inherits directly or indirectly from QObject. It is also not needed for any Qt container or smart pointer using types which are themselves metatypes.

For example, these constructs are no longer needed when using Qt 5:

Q_DECLARE_METATYPE(QList<int>)
 Q_DECLARE_METATYPE(QList<QObject*>)
 // Because MyObject* is automatically a metatype from above!
 Q_DECLARE_METATYPE(QList<MyObject*>)
 Q_DECLARE_METATYPE(QSharedPointer<<MyObject*>>)
 // Because QList<MyObject*> is automatically a metatype from above!
 Q_DECLARE_METATYPE(QVector<QList<MyObject*>>)

This is also true for types where the user does still have to use Q_DECLARE_METATYPE, for example, when the type does not inherit from QObject:

struct SomeStruct {};
 Q_DECLARE_METATYPE(SomeStruct)
 // No need for Q_DECLARE_METATYPE(QList<SomeStruct>)
 // later:
 QList<SomeStruct> structs;
 QVariant var = QVariant::fromValue(structs);

In some cases in Qt 4, it is also necessary to use the qRegisterMetaType method. The reason to need this is usually that Q_PROPERTY is used with a metatype which is not built-in (types such as int and QString are built-in and don't need to be marked as metatypes).

With the new possibility of automatically declaring certain types as metatypes, the question of whether we could automatically register them came up too. Because qRegisterMetaType only needs to be used in a small number of cases, most of which relate to QObject or Q_PROPERTY in some way, it was possible to use moc to automatically register types which have not yet been registered. So now, in Qt 5, there are even fewer reasons to have to use qRegisterMetaType.

Another new qRegisterMetaType related feature in Qt 5 is the detection of accidental ODR violations. This often does not have any effect, but can accidentally hide problems such as typos which can mysteriously make your application not work properly. Now, you will get a compile-time or runtime error if using Q_DECLARE_METATYPE and qRegisterMetaType together in a way which has undefined behavior.

Another new feature is the possibility for built-in qobject_cast-style conversion through the inherited types. For example:

MyObject *myObjectInstance = ...;
 QVariant var = QVariant::fromValue(myObjectInstance);
 // elsewhere...
 if (var.canConvert())
 {
 QObject *obj = var.value();
 // Use the properties of obj
 }

This adds features 'for free' to domain-specific languages implemented using Qt where the language is based on QObject and properties. It only works for types which inherit from QObject, and can not be generalized for a generic static_cast. The reason for that limitation is that internally it uses the generated QMetaObject of the stored type. Future versions of Qt will extend this feature in a similar way for QSharedPointer conversions.

Another nice but minor feature is that pointers to QObject derived types contained in a QVariant now print out their address and objectName when used with qDebug. For example:

QLabel* l = new QLabel;
 l.setObjectName("someLabel");
 QVariant var = QVariant::fromValue(l);
 qDebug() << var;
 // Qt 4 prints: QVariant(QLabel*, )
 // Qt 5 prints: QVariant(QLabel*, QLabel(0x7fff792fefa0, name = "someLabel") ))

The goals I wrote about elsewhere last year are now met, though the implementation is somewhat different in Qt 5. The SFINAE pattern I wrote about is used extensively to make these features possible.

CMake Config files

For many users of Qt, the CMake buildsystem tool provides advantages over the bundled qmake. Some of the differences compared to qmake were part of a presentation at the recent Qt Developer Days hosted by KDAB in Berlin. Part of the difference in how using CMake will differ when using it with Qt 4 versus Qt 5 is that 'CMake Config files' are now generated as part of the build-process of Qt itself and shipped in packages. I previously detailed what that means for users of CMake, and have added new comprehensive documentation to guide new users through the process of using CMake with Qt 5.

Although porting is required when changing from using Qt 4 to Qt 5, simple variable mappings can ease the porting burden.

Tags:

qt

14 Comments

20 - Dec - 2012

klaatu

Very nice! QEventLoopLocker sounds especially appealing. I always thought Amaroks "I'm going to keep running in systray unless you explicitly tell me otherwise" was a pretty neat workaround, but QEventLoopLocker sounds like a more purposeful solution.

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

20 - Dec - 2012

Bernhard Friedreich

Wow great work :) Thanks for KDABs involvement :)

Nice to see so many under the hood improvements also in those core areas :)

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

20 - Dec - 2012

Sandro Andrade

These are really great improvements in Qt meta-object features :) Some of them have already made things easier in my daily work. Do I still need to use Q_DECLARE_METATYPE(QList*) ? Supposing QList doesn't inherit from QObject, I gues the answer is yes, right ? :)

Extracting QObject's from QVariant's created from QObject-derived classes is awesome ! Any chance for having this also working to extract a QList from QVariant's containing QList ? Those weird reinterpret_cast's always scare me :)

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

20 - Dec - 2012

Sandro Andrade

Oops, some characteres have been removed. I mean: Do I still need to use Q_DECLARE_METATYPE(QList < QObject * > *) ?

And any chance for extracting a QList < QObject * > from a QVariant build from a QList < MyObjectDerived * > ?

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

21 - Dec - 2012

steveire

Hi there,

Yes, you still need to use Q_DECLARE_METATYPE(QList < QObject * > *)

Having a pointer to a QList is not really common enough to have explicit code for :).

I hope to make it easier to handle QList < MyObjectDerived* > but it didn't make it into Qt 5.0. We'll see what is possible for 5.1, but no guarantees I'm afraid, due to backwards compatibility.

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

21 - Dec - 2012

Sandro

Thanks ! Those new features already do a great job :)

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

29 - Dec - 2012

Sandro Andrade

Hi again,

Maybe I misunderstood what you said about qRegisterMetaType, but when using QMetaProperty::read on a property with type QObjectDerived * or QList/QSet of QObjectDerived *, I get a run-time message:

Unable to handle unregistered datatype 'QList' for property 'Teste::User::myClassList'

Do I need to run qRegisterMetaType for those cases ? I've noticed that QVariant::fromValue implictly run a qRegisterMetatype.

Thanks,

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

29 - Dec - 2012

steveire

I've just tried it, and it works for me.

Maybe try sending a minimal code example by email.

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

30 - Dec - 2012

Sandro Andrade

Hi, I've just sent you an example of that.

Thanks,

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

30 - Dec - 2012

steveire

Thanks.

The problem is that when moc is run on user.h, MyClass is only forward declared, so moc does not know it is a QObject subclass. That's a limitation of the implementation.

Sorry about that.

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

31 - Dec - 2012

Sandro Andrade

No problem, that's a good reason to use a full #include instead of forward decl.

Thanks for help :)

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

4 - Mar - 2013

Sandro Andrade

Hi there again,

I'm facing the unfortunate case of having two classes with the same name in different namespaces:

namespace QtUml {
 class QClass ...
 Q_PROPERTY(p1 ...)
 ...
 Q_PROPERTY(pn ...)
}
namespace QtMof {
 class QClass ...
 Q_PROPERTY(p1 ...)
 ...
 Q_PROPERTY(pm ...)
}
n > m

I have no explicit Q_DECLARE_METATYPE in my code, but it seems moc auto declares both as 'QClass *'. Both classes are loaded as plugins (QtMof::QClass is loaded after QtUml::QClass). I'm using qDeclareMetaType and qDeclareMetaType.

For some reason, when both plugins are loaded, the metaObject class from QtUml::QClass shows only those properties declared in QtMof::QClass (apparently because moc is also declaring it as QClass * and therefore overriding previous QClass * declaration for QtUml::QClass *).

Any hint for that issue ? Any way to tell moc to not auto-declare pointers to QObject-inheriting classes ?

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

4 - Mar - 2013

steveire

Thanks for notifying. Please report the bug to bugreports.qt-project.org.

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

4 - Mar - 2013

Sandro Andrade

I found it, it's my fault :) I was using macros for defining namespaces:

QT_BEGIN_NAMESPACE_QTMOF

And it seems MOC looks for for explicit namespace directives. When I changed it to:

QT_BEGIN_NAMESPACE
namespace QtMof {

everything works like a charm now !

Thanks anyway :)

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

I have read and agree to the privacy policy.

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • If you wish for us to erase it, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy.

Trusted Software Excellence

Expertise

Trusted Software Excellence across Desktop and Embedded

Take a glance at the areas of expertise where KDAB excels ranging from swift troubleshooting, ongoing consulting and training to multi-year, large-scale software development projects.

Find out why customers from innovative industries rely on our extensive expertise, including Medical, Biotech, Science, Renewable Energy, Transportation, Mobility, Aviation, Automation, Electronics, Agriculture and Defense.

Embedded Devices Embedded Devices

High-quality Embedded Engineering across the Stack

To successfully develop an embedded device that meets your expectations regarding quality, budget and time to market, all parts of the project need to fit perfectly together.

Learn more about KDAB's expertise in embedded software development.

Read More

Cross-platform Desktop Cross-platform Desktop

Create complex Applications for the Desktop

Where the capabilities of modern mobile devices or web browsers fall short, KDAB engineers help you expertly architect and build high-functioning desktop and workstation applications.

Read More

Modernizing Legacy Software Modernizing Legacy Software

Reduce Technical Debt

Legacy software is a growing but often ignored problem across all industries. KDAB helps you elevate your aging code base to meet the dynamic needs of the future.

Whether you want to migrate from an old to a modern GUI toolkit, update to a more recent version, or modernize your code base, you can rely on over 25 years of modernization experience.

Read More

Medical Medical

Extensible, Safety-compliant Software for the Medical Sector

Create intelligent, patient-focused medical software and devices and stay ahead with technology that adapts to your needs.

KDAB offers you expertise in developing a broad spectrum of clinical and home-healthcare devices, including but not limited to, internal imaging systems, robotic surgery devices, ventilators and non-invasive monitoring systems.

Read More

Industrial Industrial

Build on Advanced Expertise when creating Modern UIs

KDAB assists you in the creation of user-friendly interfaces designed specifically for industrial process control, manufacturing, and fabrication.

Our specialties encompass the custom design and development of HMIs, enabling product accessibility from embedded systems, remote desktops, and mobile devices on the move.

Read More

Vehicle Dashboards Vehicle Dashboards

Fluid animations and gesture-controlled UIs

Building digital dashboards and cockpits with fluid animations and gesture-controlled touchscreens is a big challenge.

In over two decades of developing intricate UI solutions for cars, trucks, tractors, scooters, ships, airplanes and more, the KDAB team has gained market leading expertise in this realm.

Read More

Security and Defense Systems

Reliable software for the public security and defense sector

KDAB is a trusted software partner for authorities and suppliers requiring ever more robust and reliable software in the public security and defense sector.

Read More

Services

Software Consulting, Development and Training

KDAB offers a wide range of services to address your software needs including consulting, development, workshops and training tailored to your requirements.

Our expertise spans cross-platform desktop, embedded and 3D application development, using the proven technologies for the job.

Software Consulting Software Consulting

Guidance for your Software Project across the Stack

Get expert advice on any phase of your project's journey, from inception to execution, across multiple platforms and hardware.

KDAB provides guidance on architectural approach, UI strategy, development tooling, test infrastructure, deployment model, runtime execution and more.

Read More

Qt Services Qt Services

Expert Qt Solutions for Your Needs

When working with KDAB, the first-ever Qt consultancy, you benefit from a deep understanding of Qt internals, that allows us to provide effective solutions, irrespective of the depth or scale of your Qt project.

Qt Services include developing applications, building runtimes, mixing native and web technologies, solving performance issues, and porting problems.

Read More

Embedded Development Embedded Development

Build rich embedded applications for your embedded UI

Turn your vision into reality and unleash the potential of your embedded development projects.

KDAB helps you navigate the complex landscape of embedded development, ensuring your software performs optimally on your chosen hardware.

Read More

Cross-platform Development Cross-platform Development

Get help with all Aspects of Desktop Applications

KDAB helps create commercial, scientific or industrial desktop applications from scratch, or update its code or framework to benefit from modern features.

Discover clean, efficient solutions that precisely meet your requirements.

Read More

3D Software 3D Software

Simplify the complexity of 3D

Creating 3D applications can be overwhelming due to terminology, visual concepts, and advanced math.

KDAB simplifies this task, providing you with the best solution for your 3D project, easing complexities and maximizing efficiency.

Read More

Developer Training Developer Training

Professional Developer Training Courses

Boost your team's programming skills with in-depth, constantly updated, hands-on training courses delivered by active software engineers who love to teach and share their knowledge.

Our courses cover Modern C++, Qt/QML, Rust, 3D programming, Debugging, Profiling and more.

Read More

Technologies

Make the right Technology Choices

The collective expertise of KDAB's engineering team is at your disposal to help you choose the software stack for your project or master domain-specific challenges.

Our particular focus is on software technologies you use for cross-platform applications or for embedded devices.

Qt / QML Qt / QML

Leading Qt Expertise

Since 1999, KDAB has been the largest independent Qt consultancy worldwide and today is a Qt Platinum partner. Our experts can help you with any aspect of software development with Qt and QML.

Read More

Modern C++ Modern C++

Deep understanding of Modern C++

KDAB specializes in Modern C++ development, with a focus on desktop applications, GUI, embedded software, and operating systems.

Our experts are industry-recognized contributors and trainers, leveraging C++'s power and relevance across these domains to deliver high-quality software solutions.

Read More

Rust Rust

Integrate Rust into your application

KDAB can guide you incorporating Rust into your project, from as overlapping element to your existing C++ codebase to a complete replacement of your legacy code.

Read More

Platforms Platforms

Unique Expertise for Desktop and Embedded Platforms

Whether you are using Linux, Windows, MacOS, Android, iOS or real-time OS, KDAB helps you create performance optimized applications on your preferred platform.

Read More

Slint Slint

A lightweight GUI toolkit

If you are planning to create projects with Slint, a lightweight alternative to standard GUI frameworks especially on low-end hardware, you can rely on the expertise of KDAB being one of the earliest adopters and official service partner of Slint.

Read More

Flutter Flutter

Flutter for Embedded and Desktop

KDAB has deep expertise in embedded systems, which coupled with Flutter proficiency, allows us to provide comprehensive support throughout the software development lifecycle.

Our engineers are constantly contributing to the Flutter ecosystem, for example by developing flutter-pi, one of the most used embedders.

Read More

3D / OpenGL / Vulkan 3D / OpenGL / Vulkan

Cutting-edge 3D / XR

Incorporating 3D into 2D UIs or creating compelling XR experiences can be challenging.

Create visually stunning, ultra-realistic 3D graphics, dynamic 2D user interfaces, or leveraging the power of hardware-accelerated computation.

The 3D experts at KDAB bring incisive know-how for your project.

Read More

Developer Tools Developer Tools

Developer Tools from KDAB

The right tools and libraries can skyrocket developers' productivity.

Take advantage of KDAB's popular open source tools for tasks including profiling, debugging and continuous integration (CI).

Read More

KDAB Labs KDAB Labs

Research & Development at KDAB

KDAB invests significant time in exploring new software technologies to maintain its position as software authority. Benefit from this research and incorporate it eventually into your own project.

Read More

Resources

Start here to browse information on the KDAB website(s) and take advantage of useful developer resources like blogs, publications and videos about Qt, C++, Rust, 3D technologies like OpenGL and Vulkan, the KDAB developer tools and more.

Blogs Blogs

KDAB engineers and designers constantly share cutting-edge technology insights with regard to Qt, QML, C++, Rust, Linux, Vulkan, OpenGL, Qt 3D, scalable UIs and more topics.

Stay up-to-date and be inspired with their blogs.

Read More

Events Events

Get a quick overview of events relevant to the software industry and with involvement of KDAB, be it as speakers, sponsors, exhibitors or organizer.

Take the opportunity to reach out to our experts directly. See you there!

Read More

Publications Publications

KDAB regularly publishes in-depth papers, brochures and other material on topics relevant to software developers and desicion makers.

Have a look at the list of KDAB publictions.

Read More

Videos Videos

The KDAB Youtube channel has become a go-to source for developers looking for high-quality tutorial and information material around software development with Qt/QML, C++, Rust and other technologies.

Click to navigate the all KDAB videos directly on this website.

Read More

Why KDAB

A software supplier you can rely on

In over 25 years KDAB has served hundreds of customers from various industries, many of them having become long-term customers who value our unique expertise and dedication.

Learn more about KDAB as a company, understand why we are considered a trusted partner by many and explore project examples in which we have proven to be the right supplier.

About KDAB About KDAB

Committed, compassionate, trustworthy

The KDAB Group is a globally recognized provider for software consulting, development and training, specializing in embedded devices and complex cross-platform desktop applications.

Read more about the history, the values, the team and the founder of the company.

Read More

Proven Excellence Proven Excellence

Customer Success Stories

When working with KDAB you can expect quality software and the desired business outcomes thanks to decades of experience gathered in hundreds of projects of different sizes in various industries.

Have a look at selected examples where KDAB has helped customers to succeed with their projects.

Read More

Trusted Partner Trusted Partner

Benefit from a strong partner network

Lasting relationships reduce frictions in software development projects and help to guarantee success.

Benefit from the established relationships KDAB has with well-selected hardware suppliers and specialized domain experts.

Read More

Better Software Better Software

Constantly improving Software Quality

KDAB is committed to developing high-quality and high-performance software, and helping other developers deliver to the same high standards.

We create software with pride to improve your engineering and your business, making your products more resilient and maintainable with better performance.

Read More

ISO 9001 ISO 9001

ISO 9001 certified software services

KDAB has been the first certified Qt consulting and software development company in the world, and continues to deliver quality processes that meet or exceed the highest expectations.

Read More

Working at KDAB Working at KDAB

Looking for a new challenge?

In KDAB we value practical software development experience and skills higher than academic degrees. We strive to ensure equal treatment of all our employees regardless of age, ethnicity, gender, sexual orientation, nationality.

Interested? Read more about working at KDAB and how to apply for a job in software engineering or business administration.

Read More

Contact

Search

CODEBROWSER

KDAB|Training