Skip to content

Posts from the ‘Qt embedded’ Category

27
Nov

Private slot implementation in pimpl pattern by Qt-way.

Introduction.

Some time before I wrote about pimp pattern by Qt-way. In that post I was trying to show you the good way of using pimpl pattern, and use it at all. Especially when you implement your own library. Binary compatibility is good idea and d-pointers help to make it easily. Now I’ll try to extend you knowledges about this pattern, and show you new useful tool for making d-pointers better and more flexible. The next post is finally will close the pimpl topic: it will be about shared d-pointers and implicit sharing. But this topic is about private slots, the mechanism, that common used by Qt classes.

What is it? And why to use it?

Private slot is extension of d-pointers. Private slots give you way to realize slots in private class, even if private class is not QObject ( it’s not QObject almast in all classes ). But public class have to be QObject. Really the slot is not Private’s class slot, it is part of public class.
Why we need slot in private class? Let’s look at some example. There is exists QAbstractScrollArea class.It’s simply displays it’s view
port widget, and move it, if it has large geometry. QAbstractScrollAreaPrivate has two QScrollBars to make opportunity to user move viewport’s widget. Ok, and what to do when user changed scrollbar’s value ? In common way we need to connect appropriate signal of scrollbar to slot of our class, that implement necessary behaviour (scroll in our case). But this slots will became available outside our class in this case. It’s not good idea to show private implementation outside. The other possible solution is to make private class derived from QObject. Don’t do this (you have very heavy reasons to do it, and private slots is not one of them)!!!
Don’t worry, Trolls made a grade solution – private slots! This is very simple and flexible way to resolve this issue.

Read moreRead more


Unique visitors to post: 132

26
Nov

Приватные слоты в паттерне Pimpl от Qt.

Вступление.

Недавно я писал по поводу реализации паттерна Pimpl в библиотеке Qt и призывал людей следовать такому подходу при разработке их собственных бибиотек. Теперь я хочу поговорить о таком понятии, как приватные слоты и тем самым продолжить эту тему. Заключительной статьей на эту тему будет реализация механизма Implicit Sharing и shared d-pointer.

Что это и зачем это нужно.

Приватные слоты – это механизм дополняющий функционал d-указателей. Он позволяет реализовать слоты для приватного класса, даже если он не является наследником от QObject (обычно он им и не является), но для этого публичный класс должен быть наследником от QObject. Тоесть по факту создается некий приватный слот в публичном классе и он непосредственно дергает нужный метод приватного класса.
Зачем это нужно? Ну рассмотрим на примере. Есть класс QAbstractScrollArea. Он просто отображает некий виджет (viewport) и обеспечивает прокрутку. Прокрутка обеспечивается с помощью двух экземпляров класса QScrollBar. Сами эти скролбары он хранит в приватном классе. Теперь проблемма: как подключить сигнал от скроллбара об изменение его позиции с классом QAbstractScrollAreaPrivate, ведь он не является QObject’ом ? Сделать его наследником от QObject – лучше не делайте это :-) . Можно сделать слот в публичном классе и повесить на него, то в таком случае это не очень красиво – так как наружу выходят слоты от внутренней реализации. Вот ту Qt-шниками был придуман достаточно разумный и элегантный подход – приватные слоты.

Read moreRead more


Unique visitors to post: 58

20
Nov

Pimpl. D-pointer. Или чеширский кот по версии Qt.

English version.

Вступление.

Qt Logo

Qt Logo

Часто в документации от Qt встречается термин Pimpl. Кроме того, те кто хоть немного копался в исходном коде Qt часто видел такие макросы как: Q_DECLARE_PRIVATE, Q_D. А также встречал так называемые приватные заголовочные файлы, название которых заканчивается на “_p.h”.
В этой статье я попробую приоткрыть ширму за всей это структурой.
Read moreRead more


Unique visitors to post: 241

27
Oct

Code less, Create more, Deploy everywhere. Indeed ? Part 1: Introduction.

Hello All. I just think about Cross-platform development of end-user application. And found that it’s much more difficult than might be. I think it’s terrible and it’s break’s IT evolution at all. :-( It’s very sad, and It’s time to think about decision.
Maybe you think I’m drank or it’s paranoia ? Maybe, But let’s see more detailed on it.

What we haver now ?

In our days we have two main branches of end-user hardware devices:
1. portable/embedded/low-resources devices
2. desktop/laptop devices

First category is handled devices, PDA, communicators, Set Top Boxes, industrial devices, Digital Secure Systems, Smart Houses, Phones, Multimedia centers, etc… Let’s call them embedded systems: ES.
The second category is personal computers and laptops. Let’s call them desktop systems: DS.

Read moreRead more


Unique visitors to post: 12