Thread: Creating an object of a class inside another class - possible?

  1. #31
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Elysia View Post
    But obviously, you just show the first window, then proceed to show the second window, then immediately return 1 (which really should be true and bool), and goes on to hiding the first dialog.
    What do you mean by true and bool? Its true because I returned 1 (a true value) from the function. Are you saying I should do something like this:
    Code:
    bool int nextDialog() {
    //code here
    //return 1 //line not needed any more?
    }
    and then
    Code:
    if (nextDialog() == true)
      sendHideRequest(dialog);
    ?
    You need to wait for some event that indicates that the "next" button has been pressed before proceeding. How that's done in Qt, I have no idea, though.
    Well, the event was supposed to be returning the 1 value (indicating the if statement is true), but for some reason it appears that the if statement calls nextDialog itself. Can I not use a function in a if statement's condition?
    Last edited by Programmer_P; 08-15-2009 at 03:12 PM.

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You can actually do:
    Code:
    bool foo () { return true; }
    if (foo()) ... ;
    Bools are good for true/false.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Ahh...ok. Well, I don't know if you caught this or not, but what my code does is only calls the nextDialog() (and hence, sendNextRequest) function when the next button is clicked. The reason is I only call nextDialog from inside nextClicked(), and nextClicked() is only called when the Next button (of the first dialog) is pressed. So that's how I know the if statement is calling nextDialog, since I can only see the second dialog when the program opens.

    But I'll try using the bool method, and maybe that will work...
    Last edited by Programmer_P; 08-15-2009 at 03:19 PM.

  4. #34
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Code:
    #include <QApplication>
    #include <QDialog>
    #include <QPushButton>
    
    class TextToSpeechDialog2 : public QDialog {
      Q_OBJECT
    public:
      TextToSpeechDialog2(void) {
        setWindowTitle("TextToSpeechDialog2"); setFixedSize(320, 240);
      }
    };
    
    class TextToSpeechDialog1 : public QDialog {
      Q_OBJECT
    public:
      TextToSpeechDialog1(void)
          : QDialog(), nextButton("Next", this) //initialize next button
      {
        setWindowTitle("TextToSpeechDialog1"); setFixedSize(320, 240);
        QObject::connect(&nextButton, SIGNAL(clicked()), this, SLOT(nextClicked()));
      }
    public slots:
      void nextClicked(void) {
        hide();         //hide TextToSpeechDialog1
        dialog2.show(); //show TextToSpeechDialog2
      }
    private:
      TextToSpeechDialog2 dialog2;
      QPushButton nextButton;
    };
    
    int main(int argc, char *argv[]) {
      QApplication app(argc, argv);
      TextToSpeechDialog1 dialog1;
      dialog1.show();
      return app.exec();
    }
    Sorry, I don't get why you'll need the global function especially why you put that inside the main which will be executed after your first dialog shown up, you may try the code above.
    Just GET it OFF out my mind!!

  5. #35
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827

    Thumbs up

    Brilliant! Absolutely fantastic!

    I can't believe I didn't see that I could call hide() directly from inside TextToSpeechDialog1. So all I had to do was remove the extra global functions, and simply go

    Code:
    hide();
    inside nextClicked();

    and it works. I was thinking I had to access it through an object of the class, and didn't think of accessing it directly...

    Many thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. array of class object
    By TomButcher in forum C++ Programming
    Replies: 5
    Last Post: 09-03-2005, 09:48 AM
  4. Base class initialization
    By VirtualAce in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2004, 04:52 AM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM