Results 1 to 3 of 3

Thread: Some questions related to Qt tutorials

  1. #1
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Some questions related to Qt tutorials

    I have some questions I collected when I was offline and doing the Qt tutorials. Please read patiently and answer. Thank you very much.

    1. Is there any effective practical difference between presence and absence of setFocusProxy in lcdrange.cpp of tutorial 08? I tried doing without it and did not see any change.

    2. In tut 08 it says:
    "It is important to only emit the angleChanged() signal when the angle really has changed."
    Why? is it just good programming practice leading to efficiency or what?

    3. In tut 09 line 56 we have:
    Qt Code:
    1. painter.translate(0, rect().height());
    To copy to clipboard, switch view to plain text mode 
    But in tut 10 line 68:
    Qt Code:
    1. painter.translate(0, height());
    To copy to clipboard, switch view to plain text mode 
    The rect() is unnecessary, right? Shouldn't it cause any inefficiency? I found that after compiling there is no difference even in the binaries!

    4. In tut 10 we have:
    Qt Code:
    1. include <QPaintEvent>
    To copy to clipboard, switch view to plain text mode 
    whereas in 09 we do not. Is there not a difference?

    5. What are the historical reasons mentioned in the QRect class reference of bottomLeft() and bottomRight() ?

    6. In tut 10 what is the effective difference between update() and update(cannonRect())? I see no problem with just update(). Then the cannonRect function is unnecessary.

    7. In tut 08 cannonfield.cpp line 49 why is "event" within /**/ ?

    8. In tut 08, I used:
    Qt Code:
    1. connect ( angle, SIGNAL ( valueChange ( int ) ), cannonField, SLOT ( setAngle ( int ) ) ) ;
    To copy to clipboard, switch view to plain text mode 
    instead of
    Qt Code:
    1. connect ( angle, SIGNAL ( valueChanged ( int ) ), cannonField, SLOT ( setAngle ( int ) ) ) ;
    To copy to clipboard, switch view to plain text mode 
    but got no compile-time error saying that there is no such signal called "valueChange ( int )". How come?

    Thanks for your patience.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Some questions related to Qt tutorials

    I'll answer those that I can without looking at the tutorial
    Quote Originally Posted by jamadagni View Post
    2. In tut 08 it says:

    Why? is it just good programming practice leading to efficiency or what?
    Yes, it's mostly a matter of efficiency, but not only. If the signal names suggests that something changed, then it should only be emitted when something changed and not when it might have changed. Consider this small example:
    Qt Code:
    1. QSpinBox *sb = new QSpinBox;
    2. QSlider *sl = new QSlider;
    3. connect(sb, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int)));
    4. connect(sl, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int)));
    To copy to clipboard, switch view to plain text mode 
    If valueChanged() was emitted every time setValue() was used - even if the new value was exactly the same as the old one, you'd end up with an infinite loop here. Making sure that the signal is emitted only when values change, the code will work correctly.

    3. In tut 09 line 56 we have:
    Qt Code:
    1. painter.translate(0, rect().height());
    To copy to clipboard, switch view to plain text mode 
    But in tut 10 line 68:
    Qt Code:
    1. painter.translate(0, height());
    To copy to clipboard, switch view to plain text mode 
    The rect() is unnecessary, right? Shouldn't it cause any inefficiency? I found that after compiling there is no difference even in the binaries!
    Yes, it should behave the same.

    4. In tut 10 we have:
    Qt Code:
    1. include <QPaintEvent>
    To copy to clipboard, switch view to plain text mode 
    whereas in 09 we do not. Is there not a difference?
    No, because some other class might already include QPaintEvent.

    6. In tut 10 what is the effective difference between update() and update(cannonRect())? I see no problem with just update(). Then the cannonRect function is unnecessary.
    The former refreshes the whole widget whereas the latter only the part where the cannon is. It might make it faster.

    7. In tut 08 cannonfield.cpp line 49 why is "event" within /**/ ?
    Because the value of event is never used in the method and leaving the variable name would cause a warning about an unused variable.

    8. In tut 08, I used:
    Qt Code:
    1. connect ( angle, SIGNAL ( valueChange ( int ) ), cannonField, SLOT ( setAngle ( int ) ) ) ;
    To copy to clipboard, switch view to plain text mode 
    instead of
    Qt Code:
    1. connect ( angle, SIGNAL ( valueChanged ( int ) ), cannonField, SLOT ( setAngle ( int ) ) ) ;
    To copy to clipboard, switch view to plain text mode 
    but got no compile-time error saying that there is no such signal called "valueChange ( int )". How come?
    Because slots are connected during runtime. The construction above is completely valid from compiler's point of view. You should get a runtime warning about a missing signal.

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

    jamadagni (17th March 2007)

  4. #3
    Join Date
    Aug 2006
    Location
    Switzerland
    Posts
    52
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Some questions related to Qt tutorials

    Quote Originally Posted by jamadagni View Post
    1. Is there any effective practical difference between presence and absence of setFocusProxy in lcdrange.cpp of tutorial 08? I tried doing without it and did not see any change.
    LCDRange consists of two widgets: QLCDNumber and QSlider. In main.cpp in MyWidget constructor you create LCDRange and call setFocus() on it. With setFocusProxy() focus is passed to QSlider contained in it. So in this example, the practical difference is right after you run the program. With setFocusProxy() slider has focus. Without setFocusProxy() you have to press Tab first.
    The Wheel weaves as the Wheel wills.

Similar Threads

  1. Sql questions
    By Nb2Qt in forum Qt Programming
    Replies: 4
    Last Post: 15th February 2007, 22:53
  2. QKeyEvent questions
    By bglidden in forum Qt Programming
    Replies: 1
    Last Post: 3rd October 2006, 06:29
  3. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32
  4. 2 Questions about layouts
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2006, 13:54
  5. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 12:25

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.