Results 1 to 10 of 10

Thread: Creating a Dialog in a Slot of QMainWindow

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Creating a Dialog in a Slot of QMainWindow

    Hello,

    I created a MainWindow and a very simple Dialog using the Qt Designer. I want to use both components with a single inheritance approach. In a Slot of the MainWindow (connected to an Action of the MainWindow) I want to create and execute an instance of the Dialog class. But when I try to compile the programm there is the error:

    release\MainWindow.o(.text+0x28f):MainWindow.cpp: undefined reference to 'Dialog::Dialog(QWidget*)'

    I think the proplem might be connected with the fact that I want to create the Dialog in a class derived from QMainWindow. In my project I previously created the Dialog in a Slot of a QAbstractTableModel and it worked fine. Than I decided that this class wasn't the right place to do this and wanted to create the Dialog in a slot of the MainWindow instead ending up with this error.

    Here are the files of a minimal example:

    MainWindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "ui_MainWindow.h"
    6.  
    7. class MainWindow : public QMainWindow {
    8. Q_OBJECT
    9.  
    10. public:
    11. MainWindow(QWidget *parent=0,Qt::WFlags flags=0);
    12.  
    13. public slots:
    14. void createDialog();
    15.  
    16. private:
    17. Ui::MainWindow *ui;
    18. };
    19.  
    20. #endif
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp
    Qt Code:
    1. #include "MainWindow.h"
    2. #include "Dialog.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent,Qt::WFlags flags){
    5. ui = new Ui::MainWindow;
    6. ui->setupUi(this);
    7.  
    8. connect(ui->actionCreate,SIGNAL(activated()),this,SLOT(createDialog()));
    9. }
    10.  
    11. void MainWindow::createDialog(){
    12. Dialog *d = new Dialog;
    13. d->exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    Dialog.h
    Qt Code:
    1. #ifndef MYDIALOG_H
    2. #define MYDIALOG_H
    3.  
    4. #include <QDialog>
    5. #include "ui_Dialog.h"
    6.  
    7. class Dialog : public QDialog {
    8. public:
    9. Dialog(QWidget *parent = 0);
    10.  
    11. };
    12.  
    13. #endif
    To copy to clipboard, switch view to plain text mode 

    Dialog.cpp
    Qt Code:
    1. #include "Dialog.h"
    2.  
    3. Dialog::Dialog(QWidget *parent = 0) : QWidget(parent){
    4. Ui::Dialog *ui = new Ui::Dialog;
    5. ui.setupUi(this);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by tilm; 13th August 2008 at 09:51.

Similar Threads

  1. Replies: 4
    Last Post: 25th August 2014, 18:05
  2. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 14:44
  3. Replies: 3
    Last Post: 18th October 2007, 08:07

Tags for this Thread

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.