Results 1 to 4 of 4

Thread: Slider not responding to Signal

  1. #1
    Join Date
    Dec 2010
    Location
    My bed
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Slider not responding to Signal

    I made a program that converts celsius to fahrenheit and vice versa. It consists of two sliders: sl_celsius: and sl_fheit, and two lcd displays lcd_celsius and lcd_fheit.
    Moving sl_celsius displays the celsius temperature in lcd_celsius and the corresponding fahrenheit temperature in lcd_fheit. As the lcd_fheit changes, the sl_fheit also moves.
    The problem is that the reverse does not occur (i.e. moving the fahrenheit slider does not cause celsius to be displayed in lcd_celsius and sl_celsius does not move either). I do not understand why this happens.

    The connections are as follows:
    Qt Code:
    1. connect(ui->sl_celsius,SIGNAL(sliderMoved(int)),ui->lcd_celsius,SLOT(display(int)));
    2.  
    3. connect(ui->sl_celsius,SIGNAL(sliderMoved(int)),this,SLOT(calculateFahrenheitTemperature(int)));
    4.  
    5. connect(this,SIGNAL(celsiusSliderMoved(int)),ui->lcd_fheit,SLOT(display(int)));
    6.  
    7. connect(this,SIGNAL(celsiusSliderMoved(int)),ui->sl_fheit,SLOT(setValue(int)));
    8.  
    9. connect(ui->sl_fheit,SIGNAL(sliderMoved(int)),ui->lcd_fheit,SLOT(display(int)));
    10.  
    11. connect(ui->sl_fheit,SIGNAL(sliderMoved(int)),this,SLOT(calculateCelsiusTemperature(int)));
    12.  
    13. connect(this,SIGNAL(fheitSliderMoved(int)),ui->lcd_celsius,SLOT(display(int)));
    14.  
    15. connect(this,SIGNAL(fheitSliderMoved(int)),ui->sl_celsius,SLOT(setValue(int)));
    To copy to clipboard, switch view to plain text mode 

    and these are the definitions for custom fucntions:
    Qt Code:
    1. void TempConverter::calculateCelsiusTemperature(int temp)
    2. {
    3. celsius = (temp - 32)*(5/9);
    4. emit fheitSliderMoved(celsius);
    5. }
    6.  
    7. void TempConverter::calculateFahrenheitTemperature(int temp)
    8. {
    9. fahrenheit = ((temp * (9/5))+32);
    10. emit celsiusSliderMoved(fahrenheit);
    11. }
    To copy to clipboard, switch view to plain text mode 

    I'd appreciate any help, thanks!
    Last edited by eLancaster; 25th December 2010 at 16:38.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Slider not responding to Signal

    One thing you should check is the output in the debugger, or in the console, if your are getting any signal/slot warnings.

    At any rate, I don't know if this is the problem or not, but what you are doing is asking for trouble, since you have a circular (recursive) signal/slot connections:
    if you move the celsius slider, it calls calculateFahrenheitTemperature() which trough changing the Fahrenheit slider value causes it to emit the sliderMoved() signal, which calls calculateCelsiusTemperature() which changes the cesius slider which calls calculateFahrenheitTemperature() (via the dlider signal/slot connection) again...

    You need some kind of "manager" that will control both sliders, and not to have this recursion.
    Once you have put such a middle object, I predict the problem will go away.
    If not, ask again.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    eLancaster (26th December 2010)

  4. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Slider not responding to Signal

    You should check the quotient of your integer division, also.

  5. The following user says thank you to norobro for this useful post:

    eLancaster (26th December 2010)

  6. #4
    Join Date
    Dec 2010
    Location
    My bed
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Slider not responding to Signal

    Yeah the problem was in the formula - I corrected it and now it works.

Similar Threads

  1. USB Keyboard is not responding in qt-embedded-4.4.3
    By grsandeep85 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 7th April 2011, 03:13
  2. Designer not responding to mouse
    By brtip in forum Newbie
    Replies: 0
    Last Post: 28th July 2010, 05:09
  3. Replies: 2
    Last Post: 21st March 2010, 09:01
  4. QGraphicsTextItem Linkactivated not responding
    By Pancho in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2009, 22:39
  5. Window not responding
    By markcole in forum Qt Programming
    Replies: 10
    Last Post: 18th April 2007, 21:53

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.