Results 1 to 6 of 6

Thread: Trapping action from an 'SDI' app

  1. #1
    Join Date
    Jul 2008
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Trapping action from an 'SDI' app

    I have found post from users having similar problems displaying a form from another form/class when they used the designer. It seems easier to do this straight from code like the textEditor demo. However, I have designed an app in the designer as well as an about box and I would like to use them.

    The problem is that since I can't change the header created by the designer, how do I create a custom slot that the button click action will call without modifying the generated header file?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Trapping action from an 'SDI' app

    Did your read the docs on using Designer generated forms in your application?

  3. #3
    Join Date
    Jul 2008
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trapping action from an 'SDI' app

    Yes, but I did not find an example that shows how to get around this problem. Do you have a particular example in mind? The best way I can find around this problem so far is to base my app off of the text editor demo app.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Trapping action from an 'SDI' app

    Honestly I don't see the problem Could you elaborate what _is_ the problem? Did you implement a widget class for each of the Designer generated components? What did you do next? What problem did you face?

  5. #5
    Join Date
    Jul 2008
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trapping action from an 'SDI' app

    Sorry, I had a hard time putting this problem into words.

    I figured it out on my own... finaly. I was not aware that one could create one's own protection level keywords and when I was looking at the help files I didn't notice the
    Qt Code:
    1. public slots:
    To copy to clipboard, switch view to plain text mode 
    keyword.

    I created a canonical version of the solution which I will now post for posterity
    ...
    Errrr... Well, I can't seem to attach the file.

    I guess I'll just try to summarize what I did here.

    I created a "Main Window" form in the Qt Designer and changed it's object name to "QT_DesignerTestWindow". I added a menu item called "Launch some dialog box". The designer automatically created the action "actionLaunch_some_dialog_box".

    I also created a Dialog and changed its object name to "SomeDialog".

    I used qmake to create the .h files.

    I created a main.cpp shown below.

    I created a class derived from QMainWindow called MyMainWindow and added a function to that class in the 'private slots' protection level scope to act as my custom 'slot' (event callback function) also shown below.

    Here is the code:

    Qt Code:
    1. // main.cpp
    2. #include <QApplication>
    3.  
    4. // include the Designer derived header
    5. #include "ui_QT_designer_test.h"
    6.  
    7. // include the QMainWindow subclass header
    8. #include "MyMainWindow.h"
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. QApplication app(argc, argv);
    13.  
    14. MyMainWindow* mainWin = new MyMainWindow();
    15.  
    16. Ui::QT_DesignerTestWindow designerTestWindow;
    17. designerTestWindow.setupUi(mainWin);
    18.  
    19. // attempt to setup the slot to show the dialog box
    20. QObject::connect(designerTestWindow.actionLaunch_some_dialog_box,
    21. SIGNAL(triggered()),
    22. mainWin, SLOT( showDialog() ));
    23.  
    24. mainWin->show();
    25. return app.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // MyMainWindow.h
    2. #ifndef MYMAINWINDOW_H
    3. #define MYMAINWINDOW_H
    4.  
    5. #include <QMainWindow.h>
    6.  
    7. class MyMainWindow : public QMainWindow
    8. {
    9. Q_OBJECT
    10. public:
    11. MyMainWindow();
    12. private slots:
    13. void showDialog();
    14. };
    15. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // MyMainWindow.cpp
    2. #include "mymainwindow.h"
    3. #include "ui_SomeDialogBox.h"
    4.  
    5. MyMainWindow::MyMainWindow( )
    6. {
    7.  
    8. }
    9. void MyMainWindow::showDialog()
    10. {
    11. QDialog* showMe = new QDialog();
    12. Ui::SomeDialog dialog;
    13. dialog.setupUi(showMe);
    14. showMe->show();
    15. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Trapping action from an 'SDI' app


Similar Threads

  1. Replies: 12
    Last Post: 21st November 2008, 04:42
  2. Setting statusBar ignoring action tooltips
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 11th October 2007, 13:07
  3. get Text from Popupmenu action
    By raphaelf in forum Newbie
    Replies: 6
    Last Post: 11th October 2006, 15:24
  4. singnal and action
    By mickey in forum Newbie
    Replies: 1
    Last Post: 9th July 2006, 18:15
  5. No action checked in an exclusive action group
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 13th February 2006, 06:19

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.