PDA

View Full Version : Some questions in Qt's Source Code



vql
16th November 2007, 12:48
I want to develop some widgets for my project, I read Qt's widget source code & have some questions in programming:

1. The constructor of QAbstractButton:


explicit QAbstractButton (QWidget *parent = 0)

What is the purpose and the meaning to using the keyword explicit in constructor?

2. In the function QToolButtonPrivate::popupTimerDone(), some commands I don't understand:


QPointer<QMenu> actualMenu; //the type of actualMenu is'n a pointer
...
if (...)
actualMenu = menuAction->menu();
else
actualMenu = new QMenu(q); //but in this code, it used as a pointer


3. The relationship between QToolButton & QToolButtonPrivate (similar for other classes).

4. Using macro:


#define QTTR_NOOP(x) (x) // this macro has the result
#define Q_DOC_PROPERTY(text) // but this macro doesn't have the result




#define Q_D(Class) Class##Private *const d=d_func()
#define Q_Q(Class) Class *const q=q_func()

I don't understand the declare of these macros. Please explain it.


Thanks alot.

jpn
16th November 2007, 13:16
1. An explicit constructor makes sure no such statement (implicit conversion) is accepted:

QWidget widget = new QWidget;
Otherwise compiler would accept the above statement because QWidget has a constructor that takes QWidget* (parent).

2. Take a look at QPointer docs. QPointer is a helper class that provides a guarded pointer.

3. See our wiki: Private implementation (http://wiki.qtcentre.org/index.php?title=Private_implementation).

4. Many macros in Qt are just markers for meta-object compiler (http://doc.trolltech.com/4.3/moc.html). That's why many of them are defined as empty.

DeepDiver
16th November 2007, 13:18
Again too fast for me! ;-)

vql
16th November 2007, 14:04
See our wiki: Private implementation.

Please give me your suggestion about programming technical like as easily maintainance.
Example: Qt is written in which pattern?

At the moment, I need to write some custom widgets for my application, example writting a widget like QDockWidget but it has a button to set AutoHide (similar in VS2005). Please give me some guidelines how to design it? Do you have some source codes for custom widgets? Thanks

jpn
16th November 2007, 16:45
Again too fast for me! ;-)
Sowwy! :p


Please give me your suggestion about programming technical like as easily maintainance.
Example: Qt is written in which pattern?
Sorry, what do you mean? I'm sure there is a bunch of various design patterns being used here and there in Qt.

Private implementation is rather a programming idiom. Pimpl is used all over Qt mainly because it gives the possibility to maintain binary backwards compatibility. As a negative side effect, pimpl causes tiny runtime overhead and increases complexity. You shouldn't use it because you find it cool. You should use it only if you find it somehow useful. ;)


Do you have some source codes for custom widgets?

wwWidgets (http://www.wysota.eu.org/wwwidgets/)
Qxt (http://www.libqxt.org/)

vql
17th November 2007, 08:46
http://www.wysota.eu.org/wwwidgets/


This link is die. What happen??? Thanks.