Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: How to call a dialog from a mainwindow

  1. #1
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Question How to call a dialog from a mainwindow

    I want to build an interface and I need to link a pushbutton in a mainwindow with a dialog. Both were made in Qt Designer. I tried some answers that I saw in others thread but I think it doesn't help me. So, here it goes my codes:
    Mainwindow: telainicial (.h/.cpp)
    Dialog: simples (.h/.cpp)

    telainicial.h
    Qt Code:
    1. #ifndef TELAINICIAL_H
    2. #define TELAINICIAL_H
    3.  
    4. #include <QMainWindow>
    5. #include "ui_telainicial.h"
    6.  
    7. class telainicial : public QMainWindow, public Ui::telainicial {
    8. Q_OBJECT
    9. public:
    10. telainicial(QWidget *parent = 0);
    11. private slots:
    12. void telasimples();
    13. };
    14.  
    15. #endif // TELAINICIAL_H
    To copy to clipboard, switch view to plain text mode 

    telainicial.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include "telainicial.h"
    3. #include "simples.h"
    4.  
    5. telainicial::telainicial(QWidget *parent) :
    6. QMainWindow(parent)
    7.  
    8. {
    9. setupUi(this);
    10.  
    11. connect(lentesimplesButton, SIGNAL(clicked()), this, SLOT(telasimples()));
    12.  
    13. }
    14.  
    15. void telainicial::telasimples(){
    16.  
    17. //code goes here
    18.  
    19. };
    To copy to clipboard, switch view to plain text mode 

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

    simples.cpp
    Qt Code:
    1. #include "simples.h"
    2. #include <QtGui>
    3.  
    4. simples::simples(QWidget *parent) :
    5. QDialog(parent)
    6.  
    7. {
    8. setupUi(this);
    9. }
    To copy to clipboard, switch view to plain text mode 

    The mains files are similiar like this:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "telainicial.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. telainicial mainwindow;
    8. mainwindow.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Can somebody help me?
    Last edited by wysota; 18th May 2010 at 21:38. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    I've tried:
    simples dialog(this);
    dialog.exec();

    But it fails. The follow problem is detected:
    undifined reference to 'simple::simple(QWidget*)'
    undifined reference to 'vtable for simples'
    undifined reference to 'vtable for simples'
    collect2: Id returned 1 exit status

    Someone knows what is it?

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

    Default Re: How to call a dialog from a mainwindow

    Run qmake and then build your program again. Btw. your class is called "simples" and you are calling the constructor as "simple".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    My mistake. The follow problem was detected:
    undifined reference to 'simples::simples(QWidget*)'

    It's not a problem about compilation I think. I'm using the Qt Creator to do everything, like designer the ui files and compile the program. Is there any problem to do it?

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

    Default Re: How to call a dialog from a mainwindow

    Again, check if you actually implemented the simples constructor.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    Yes, it works individually. But not when I call it by mainwindow. All my constructors are correct. I just don't know what to do... I've tried everything... Is it better to make the .pro file in the Qt Command Prompt? If you can run my codes on your pc (try to do it in Qt Creator)...

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

    Default Re: How to call a dialog from a mainwindow

    What "works individually"? The .pro file is not an issue here, the linker can't find the implementation of your constructor. Could you post the contents of the offending method?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    I don't know exactly what are you asking for. I'm a beginner. Can I send my files to you by email? Sorry bother you, but it's important... :/

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

    Default Re: How to call a dialog from a mainwindow

    Please post the body of the constructor of class "simples". I hope you know what a constructor is... If not, you should first learn at least basics of C++ before taking on Qt.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    I try to search in my files about C++ something connect to constructor class but I don't find a good answer. So, I again ask you with you can give me a example of constructor class. I'm still lost here. The following compile output appear when I run telainicial mainwindow:

    g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\TelaPrincipal.exe debug/main.o debug/telainicial.o debug/moc_telainicial.o -L"f:\QT\2010.02.1\qt\lib" -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtOpenGLd4 -lQtGuid4 -lQtCored4
    mingw32-make[1]: Leaving directory `C:/Users/Luiz Paulo/Documents/TelaPrincipal'
    mingw32-make: Leaving directory `C:/Users/Luiz Paulo/Documents/TelaPrincipal'
    [r]debug/telainicial.o:C:\Users\Luiz Paulo\Documents\TelaPrincipal/telainicial.cpp:16: undefined reference to `simples::simples(QWidget*)'
    debug/telainicial.o: In function `~simples':
    C:\Users\Luiz Paulo\Documents\TelaPrincipal/simples.h:7: undefined reference to `vtable for simples'
    C:\Users\Luiz Paulo\Documents\TelaPrincipal/simples.h:7: undefined reference to `vtable for simples'
    collect2: ld returned 1 exit status
    mingw32-make[1]: *** [debug\TelaPrincipal.exe] Error 1
    mingw32-make: *** [debug] Error 2
    Exited with code 2.
    Error while building project TelaPrincipal
    When executing build step 'Make'[/r]

  11. #11
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    1) run qmake from the menu
    2) rebuild your project
    3) if it still doesn't work, post simples.h and simples.cpp if they are now different to your first post

  12. #12
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    It's already posted on top. Can you see? There are 4 codes... 2 of them are this codes...

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

    Default Re: How to call a dialog from a mainwindow

    My bet is you didn't add simples.cpp to SOURCES in your project file. At least I can't see simples.o being linked into the binary.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    Can be... now I tried it but the compilation stop to work and when I check the compile output this message was shown:
    Running build steps for project TelaPrincipal...
    Starting: f:/qt/2010.02.1/qt/bin/qmake.exe C:/Users/Luiz Paulo/Documents/TelaPrincipal/TelaPrincipal.pro -spec win32-g++ -r
    c:\Users\Luiz Paulo\Documents\TelaPrincipal\TelaPrincipal.pro:15 : Parse Error ('simples.cpp')
    Error processing project file: C:/Users/Luiz Paulo/Documents/TelaPrincipal/TelaPrincipal.pro
    Exited with code 3.
    Error while building project TelaPrincipal
    When executing build step 'QMake'

    Just one doubt... Which simples's files have to be in the same folder that the mainwindow's folder? Cause when I made both, I made it individually, so each one have a specific folder. But, I copy and put the simples.h, simples.cpp, ui_simples.h in the mainwindow's folder...

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

    Default Re: How to call a dialog from a mainwindow

    Did you add simples.cpp to the SOURCES variable or did you just put it in the project file in a random place?

    You can place the actual files anywhere you want as long as you tell the compiler where to find them.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    How I tell the compiler where is the dialog files? Sorry the stupid question... I'm noob about Qt...

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

    Default Re: How to call a dialog from a mainwindow

    You need a proper project file. Could you post its contents?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #18
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    The files .pro are below:

    telainicial.pro:
    qmake Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2010-05-14T10:13:43
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += opengl
    8.  
    9. TARGET = TelaPrincipal
    10. TEMPLATE = app
    11.  
    12.  
    13. SOURCES += main.cpp\
    14. telainicial.cpp
    15. simples.cpp
    16.  
    17. HEADERS += telainicial.h
    18.  
    19. FORMS += telainicial.ui
    To copy to clipboard, switch view to plain text mode 

    simples.pro:
    qmake Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2010-05-14T10:47:49
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += opengl
    8.  
    9. TARGET = LenteSimples
    10. TEMPLATE = app
    11.  
    12.  
    13. SOURCES += main.cpp\
    14. simples.cpp
    15.  
    16. HEADERS += simples.h
    17.  
    18. FORMS += simples.ui
    To copy to clipboard, switch view to plain text mode 

    Are this files you want to see?
    Last edited by wysota; 27th May 2010 at 14:26.

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

    Default Re: How to call a dialog from a mainwindow

    Look at your first project file. simples.cpp is not part of the SOURCES variable.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #20
    Join Date
    May 2010
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to call a dialog from a mainwindow

    It was missing a "\" after telainicial.cpp... I corrected it.
    But where I put the local where the dialog (simples) is located?

Similar Threads

  1. Open Dialog from MainWindow.
    By halvors in forum Qt Programming
    Replies: 8
    Last Post: 1st April 2010, 01:09
  2. Passing Pixmaps between MainWindow and Dialog
    By ramstormrage in forum Qt Programming
    Replies: 28
    Last Post: 20th April 2008, 13:32
  3. Communication between MainWindow and a dialog
    By Backslash in forum Newbie
    Replies: 9
    Last Post: 3rd August 2007, 04:27
  4. Opening a Dialog from a MainWindow FileMenu
    By nbkhwjm in forum Newbie
    Replies: 4
    Last Post: 17th April 2007, 12:24
  5. how to call another dialog using menubar
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 16th April 2007, 14:28

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.