Results 1 to 9 of 9

Thread: Absolute beginner in need of help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Absolute beginner in need of help

    Not a problem, that's what these forums are for.

    To call the second window you need to first instantiate the calling window and then execute it. It might look like this:

    Qt Code:
    1. void MainWindow::openNewWindow()
    2. {
    3. EditWindow myEditWindow(); // call the constructor of the second window
    4. myEditWindow.exec(); // This executes the window, and it will pop up
    5.  
    6. if (myEditWindow.result == QDialog::Accepted)
    7. {
    8. // Write your code here to retrieve what ever you want from the second window.
    9. // In the Second window you will need to create a slot for accept(), code below
    10. }
    11.  
    12. //You can then close or hide the second window
    13. myEditWindow.close();
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    In the Second window write the slot for accept() and link it to the 'clicked' signal (This depends on the buttons you have on your ui to close the second window Eg OK | Cancel or is it more buttons Eg: Save | Save All | Cancel).
    Using the accept() helps to link it to the appropriate button

    EditWindow.h file

    Qt Code:
    1. slot
    2. accept(); // For OK or Save
    3. reject(); // For cancel
    To copy to clipboard, switch view to plain text mode 

    EditWindow.cpp file
    Qt Code:
    1. connect (ui.OKButton, SIGNAL(clicked()), this, SLOT(accept()));
    2.  
    3. void EditWindow::accept()
    4. {
    5. QDialog::accept();
    6. //And whatever other code you might want to put here Eg validate before closing the window etc
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    Read the documents (Qt Assistant) for QDialog() and you will see the other slots there Eg open(), exec() etc

    Good luck!
    Last edited by qtUser500; 6th November 2009 at 16:38.

  2. #2
    Join Date
    Nov 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Absolute beginner in need of help

    That was just what I've been looking for! Thank you very much!

    I will read the documentation for QDialog as I'm not completely sure about what's actually happening here.

    Thanks again

    Regards,

    André

  3. #3
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Absolute beginner in need of help

    U r welcome
    A good place to start is reading the documentation.
    Search for 'An Overview of Qt's Examples' in QT Assistant and U will get an idea of how things work.

  4. #4
    Join Date
    Nov 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Absolute beginner in need of help

    I'm doing something similar but I'm lost in some aspects... Could you put the code of the EditWindow Class. Thanks!

  5. #5
    Join Date
    Nov 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Absolute beginner in need of help

    Here goes:

    Qt Code:
    1. EditWindow::EditWindow(QWidget* parent): QDialog(parent){
    2.  
    3. // Layout as you prefer it
    4.  
    5. connect(sendButton, SIGNAL(clicked()), this, SLOT(accept()));
    6.  
    7. }
    8.  
    9. void EditWindow::accept(){
    10. QDialog::accept();
    11. }
    12.  
    13. QString EditWindow::getText(){
    14. return textEdit->text();
    15. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Nov 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Absolute beginner in need of help

    I've tried to do this but I have an error with the code line "myEditWindow.exec();":
    Error 1 error C2228: the left operate of '.exec' must have class/struct/union.

    Any idea please?

  7. #7
    Join Date
    Nov 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Absolute beginner in need of help

    I'm a newbie in Qt, so if anyone more qualified than me could answer, that would be nice.

    But the error message say that the left operate of myEditWindow.exec() must be of a class, etc. How did you declare myEditWindow?

    I did it this way from my MainWindow class:
    Qt Code:
    1. EditWindow ew(this);
    2. ew.exec();
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Nov 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Absolute beginner in need of help

    Thank you very much! The mistake was here. I forgot to put "this". I'm a newbie in Qt too, and I'm plenty of doubts and troubles...

    Now, I will try to put some buttons and other widgets in the second window. I hope that I don't disturb so much with my questions. Thanks a lot!

Similar Threads

  1. cannot find -lQtGui -QT Beginner Help Needed
    By nsa in forum Installation and Deployment
    Replies: 5
    Last Post: 18th July 2009, 07:31
  2. Absolute widget coordinates
    By rbp in forum Qt Programming
    Replies: 4
    Last Post: 28th January 2009, 04:30
  3. Beginner C++ question
    By masoroso in forum General Programming
    Replies: 2
    Last Post: 19th April 2006, 14:15
  4. QT4 beginner Fatal Error
    By Remyfr in forum Installation and Deployment
    Replies: 3
    Last Post: 11th March 2006, 01:48
  5. return of absolute coordinates in svg-graphics
    By hulk in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2006, 12:23

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.