Some questions in Qt's Source Code
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:
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:
Code:
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:
Code:
#define QTTR_NOOP(x) [B](x)[/B] // this macro has the result
#define Q_DOC_PROPERTY(text) // but this macro doesn't have the result
Code:
#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.
Re: Some questions in Qt's Source Code
1. An explicit constructor makes sure no such statement (implicit conversion) is accepted:
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.
4. Many macros in Qt are just markers for meta-object compiler. That's why many of them are defined as empty.
Re: Some questions in Qt's Source Code
Again too fast for me! ;-)
Re: Some questions in Qt's Source Code
Quote:
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
Re: Some questions in Qt's Source Code
Quote:
Originally Posted by
DeepDiver
Again too fast for me! ;-)
Sowwy! :p
Quote:
Originally Posted by
vql
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. ;)
Quote:
Do you have some source codes for custom widgets?
Re: Some questions in Qt's Source Code
Quote:
Originally Posted by
jpn
This link is die. What happen??? Thanks.