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
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

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

    hard to tell without knowing how you instantiate Gain and how you tried to connect it.

    Btw, if you want to convert the value to be in the floating point range of 0 to 1 I would do that right there in Gain where you have access to the slider's range.
    I.e. Gain::value(), setValue() and valueChanged() would all deal with the 0..1 range, which they then map to the actual range of the slider.

    This allows you to change the "precision" at any time just by changing the slider's range.

    Cheers,
    _

  2. #2

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

    Thanks for the reply.

    Well, for instance, in sine.cpp I tried this:

    Qt Code:
    1. int tick( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *dataPointer )
    2. {
    3. Gain *volume = new volume;
    4.  
    5. SineWave *sine = (SineWave *) dataPointer;
    6. register StkFloat *samples = (StkFloat *) outputBuffer;
    7. for ( unsigned int i=0; i<nBufferFrames; i++ )
    8. *samples++ = (sine->tick() * vel) * volume->valueChanged() / 100;
    9.  
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

    This results in a number of errors including "no matching function for call to 'Gain::valueChanged()'" and "cannot convert 'int*' to 'gain*' in initialization". So I'm asking a very general question. What is a good way to instantiate Gain in the first place in any c++ code? Any ideas or links to examples? I can't seem to find anything useful about this on the internet, probably because I don't know enough to google the right questions.

  3. #3
    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?

  4. #4

    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.