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

  1. #31
    Programming Ninja In-T...
    Join Date
    May 2009
    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:
    bool int nextDialog() {
    //code here
    //return 1 //line not needed any more?
    and then
    if (nextDialog() == true)
    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
    Join Date
    Oct 2007
    Inside my computer
    You can actually do:
    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
    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
    #include <QApplication>
    #include <QDialog>
    #include <QPushButton>
    class TextToSpeechDialog2 : public QDialog {
      TextToSpeechDialog2(void) {
        setWindowTitle("TextToSpeechDialog2"); setFixedSize(320, 240);
    class TextToSpeechDialog1 : public QDialog {
          : 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; //show TextToSpeechDialog2
      TextToSpeechDialog2 dialog2;
      QPushButton nextButton;
    int main(int argc, char *argv[]) {
      QApplication app(argc, argv);
      TextToSpeechDialog1 dialog1;;
      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

    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

    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