Results 1 to 4 of 4

Thread: Question about tutorial no. 6

  1. #1
    Join Date
    Aug 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Question about tutorial no. 6

    Hi all,
    I'm running tutorial number 6: http://doc.trolltech.com/4.4/tutorials-tutorial-t6.html
    Inside the LCDRange constructor there is the following:
    Qt Code:
    1. slider->setValue(0);
    2. connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT(display(int)));
    To copy to clipboard, switch view to plain text mode 
    however, I think it doesn't work as expected...at least, on startup: lcd displays the correct number when the slider moves, but it doesn't happen when slider->setValue(0), or generally, slider->setValue(some int) is executed.
    For example
    Qt Code:
    1. slider->setValue(45);
    2. connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT(display(int)));
    To copy to clipboard, switch view to plain text mode 
    moves the slider to right position, but lcd displays 0.
    Instead, moving connect statement before slider->setValue()
    Qt Code:
    1. connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT(display(int)));
    2. slider->setValue(0);
    To copy to clipboard, switch view to plain text mode 
    does the trick, so lcd displays 45 correctly.

    Can I have some explanation of this ?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Question about tutorial no. 6

    setValue emits a signal valueChanged, but in this case
    Qt Code:
    1. slider->setValue(45);
    2. connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT(display(int)));
    To copy to clipboard, switch view to plain text mode 
    the signal is not handled, because there is no connection yet insted of this case
    Qt Code:
    1. connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT(display(int)));
    2. slider->setValue(45);
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    jacopo (26th August 2009)

  4. #3
    Join Date
    Aug 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Question about tutorial no. 6

    Yeah...so easy to understand.
    Thanks !!

  5. #4
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Question about tutorial no. 6

    Qt Code:
    1. slider->setValue(45);
    2. connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT(display(int)));
    To copy to clipboard, switch view to plain text mode 

    In fact, this is a possible way to set default values without triggering the slots those signals are connected to.

Similar Threads

  1. Replies: 0
    Last Post: 31st May 2009, 16:51
  2. Plugin implementation question
    By JPNaude in forum Qt Programming
    Replies: 12
    Last Post: 27th August 2008, 20:24
  3. Current tutorial on qt-opensource installation for Visual Studio 2005 / 2008
    By ntessore in forum Installation and Deployment
    Replies: 1
    Last Post: 16th May 2008, 12:15
  4. Exceptions / setjmp/longjmp question
    By Aceman2000 in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2008, 17:14

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
  •  
Qt is a trademark of The Qt Company.