CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2012
    Posts
    5

    Please help Inheritance Problems

    Sorry if this is a beginner topic and ive posted it in the wrong place, I am a complete begginer. I'm using Juce and want to make a load button class but having trouble getting it to inherit from a class like FileChooser so i can use it to select an audio file. Can someone point me in the write direction i'm really struggling to understand JUCE api documentation and topics like pointers.

    here is the cpp and h sections of my load button so far which ive succesfully managed to build and make clickable to callback function which prints hello world. can anyone code me a callback function which loads in an audio file or just a file as a starting point.


    #ifndef H_BUTTON
    #define H_BUTTON

    #include <juce.h>
    #include "LoadButton.h"


    /**
    play button component for the applicaiton
    */
    class LoadButton : public TextButton,
    public Button::Listener

    {
    public:
    //==============================================================================
    /**
    Constructor
    */
    LoadButton();

    /**
    Destructor
    */
    ~LoadButton();



    void buttonClicked (Button* button);




    private:
    //==============================================================================
    //Add data members here

    int button;

    };

    #endif //H_BUTTON



    #include "LoadButton.h"

    LoadButton::LoadButton()
    {
    addListener(this);
    }

    LoadButton::~LoadButton()
    {


    }


    void LoadButton::buttonClicked(Button* button)
    {







    printf("hello world");
    }


    Further guidance on JUCE classes can be sought here for those better at c++ than me but not familiar with JUCE.

    http://www.rawmaterialsoftware.com/api/

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Please help Inheritance Problems

    I don't know anything about Juice, but what you're describing on the surface doesn't sound like something you'd use inheritance for.

    Seems like you just want a button that when clicked invokes a file selection dialog. Is that correct? If it is you just want to create an instance of FileChooser in your button's click event handler.

  3. #3
    Join Date
    Jan 2012
    Posts
    5

    Re: Please help Inheritance Problems

    i'm really new to C++ and any sort of programming just been thrown in at the deep end. would you be able to help me in how i'd go about doing this?

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Please help Inheritance Problems

    Quote Originally Posted by SUPERcuulWOWZASUPERcuulWOWZA View Post
    i'm really new to C++ and any sort of programming just been thrown in at the deep end. would you be able to help me in how i'd go about doing this?
    I don't even know what Juice is, but it looks like you already have a click handler set up. Look at the documentation for your FileChooser class if that's what it's called and see if there's an example of how it works.

  5. #5
    Join Date
    Jan 2012
    Posts
    5

    Re: Please help Inheritance Problems

    thanks for your help so far. i've successfully done this i think and stored it in a variable within my loading button class. do you know how i can then use this variable within a different class called play button. is it to do with pointers? this was my solution to my initial question.


    #include "LoadButton.h"

    LoadButton::LoadButton()
    {
    addListener(this);
    }

    LoadButton::~LoadButton()
    {


    }


    void LoadButton::buttonClicked(Button* button)
    {


    FileChooser pedoFileChooser ("Choose an Audio File", File::nonexistent, String::empty, true);

    if (pedoFileChooser.browseForFileToOpen ())
    {
    File pedoFile (pedoFileChooser.getResult());
    }




    }


    I want to use the variable pedofile in another class. how do i do this

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Please help Inheritance Problems

    pedoFile is a really unfortunate name for a variable.

    Again, I don't know what Juice is or what OS you're using, but in Windows programming, typically a button will belong to a dialog class and the dialog will handle the button's click rather than the button itself. If you can set it up that way, then the parent window of the buttons would have be responsible for creating and owning the FileChooser. Failing that approach, you could make the FileChooser a member of your button rather than just created locally in the click handler.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured