Results 1 to 5 of 5

Thread: How to Route a Horizontal Slider Value to My Code?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to Route a Horizontal Slider Value to My Code?

    The "no matching function" error arises because valueChanged() is a signal and its generated code is declared in the protected section of the class. If you want the value from the slider object directly then you want the value() function, not the signal indicating it has changed.

    I assume that the "cannot convert 'int*' to 'gain*' in initialization" relates to this line:
    Qt Code:
    1. Gain *volume = new volume;
    To copy to clipboard, switch view to plain text mode 
    The LHS of this is type "Gain*". Since there's no class called "volume" the compiler has assumed an int so the RHS is type "int*". It's not entirely clear what you are trying to achieve here with this circular reference. If, as I suspect, you intended to create a new Gain object:
    Qt Code:
    1. Gain *volume = new Gain;
    To copy to clipboard, switch view to plain text mode 
    then, had you succeeded, you would have always had value() == 50 from a slider that the user neither saw nor interacted with.

    In a normal Qt program you would have a UI built containing widgets like your slider, ideally quite separate from the code that actually does substantial stuff in response. You can use Designer or hand code that UI. You would connect() the valueChanged() signal of your slider to a slot that reacts immediately to the changed value, for example pushing a new volume figure into your generator code. Assuming the tick() routine is part of the code you have pushed to another thread you could put the receiving slot in that QObject and store the current volume figure as a member variable in the generator thread.

    Unless you want to do something like anda_skoa suggests to get a floating point or logarithmic slider then it strikes me that your Gain class could simply be a QSlider subclass, something like:
    Qt Code:
    1. class Gain: public QSlider
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit Gain(QWidget *p = 0): QSlider(Qt::Horizontal, p) {
    6. setRange(1, 100);
    7. setValue(50);
    8. }
    9. };
    To copy to clipboard, switch view to plain text mode 
    Do you want to allow a zero volume?

  2. #2

    Default Re: How to Route a Horizontal Slider Value to My Code?

    Yeah, I really meant

    Qt Code:
    1. Gain *volume = new Gain;
    To copy to clipboard, switch view to plain text mode 

    I'll look into implementing the gui with Qt Designer, since I'm still having no luck. Thanks.

Similar Threads

  1. Code for Horizontal spacer
    By Gary7 in forum Newbie
    Replies: 2
    Last Post: 15th August 2012, 04:52
  2. Using GoogleMaps to show route?
    By Terreox in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2012, 22:56
  3. Replies: 0
    Last Post: 20th February 2012, 15:31
  4. Replies: 2
    Last Post: 21st March 2010, 09:01

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.