Results 1 to 6 of 6

Thread: Some questions in Qt's Source Code

  1. #1
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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:
    Qt Code:
    1. explicit QAbstractButton (QWidget *parent = 0)
    To copy to clipboard, switch view to plain text mode 
    What is the purpose and the meaning to using the keyword explicit in constructor?

    2. In the function QToolButtonPrivate:opupTimerDone(), some commands I don't understand:
    Qt Code:
    1. QPointer<QMenu> actualMenu; //the type of actualMenu is'n a pointer
    2. ...
    3. if (...)
    4. actualMenu = menuAction->menu();
    5. else
    6. actualMenu = new QMenu(q); //but in this code, it used as a pointer
    To copy to clipboard, switch view to plain text mode 

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

    4. Using macro:
    Qt Code:
    1. #define QTTR_NOOP(x) [B](x)[/B] // this macro has the result
    2. #define Q_DOC_PROPERTY(text) // but this macro doesn't have the result
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #define Q_D(Class) Class##Private *const d=d_func()
    2. #define Q_Q(Class) Class *const q=q_func()
    To copy to clipboard, switch view to plain text mode 
    I don't understand the declare of these macros. Please explain it.


    Thanks alot.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Some questions in Qt's Source Code

    1. An explicit constructor makes sure no such statement (implicit conversion) is accepted:
    Qt Code:
    1. QWidget widget = new QWidget;
    To copy to clipboard, switch view to plain text mode 
    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.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    vql (16th November 2007)

  4. #3
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Some questions in Qt's Source Code


    Again too fast for me! ;-)

  5. #4
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Some questions in Qt's Source Code

    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

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Some questions in Qt's Source Code

    Quote Originally Posted by DeepDiver View Post
    Again too fast for me! ;-)
    Sowwy!

    Quote Originally Posted by vql View Post
    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?
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    vql (17th November 2007)

  8. #6
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Some questions in Qt's Source Code

    Quote Originally Posted by jpn View Post
    This link is die. What happen??? Thanks.

Similar Threads

  1. Replies: 3
    Last Post: 8th September 2007, 11:06
  2. Qte source code
    By Gaurav vyas in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 1st July 2007, 15:11
  3. Making source code available
    By vermarajeev in forum General Discussion
    Replies: 1
    Last Post: 29th June 2007, 23:01
  4. Source code in qt-win-eval
    By Max Yaffe in forum Newbie
    Replies: 3
    Last Post: 12th April 2007, 15:17
  5. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 22:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.