Page 1 of 6 123 ... LastLast
Results 1 to 20 of 105

Thread: Problem displaying my main window

  1. #1
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem displaying my main window

    Hi. I've got a question. I have created my main window using designer and translated it into Qt code. So after translations I received a ui_Maker.h file:

    http://www.insidetennis.yoyo.pl/ntd.txt

    And how can I display this main window (called MainWindow) ?
    I tried this in main.cpp:
    Qt Code:
    1. #include "ui_Maker.h"
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. MainWindow->show();
    7. return app.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 
    but there appear error that MainWindow is undeclared. What did I do wrong? And how can I correct it? Btw. my test.pro file:
    Qt Code:
    1. CONFIG += qt
    2. HEADERS += ui_Maker.h
    3. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    Regards
    Last edited by wysota; 12th May 2007 at 22:20. Reason: Changed [qtclass] to [code]

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem displaying my main window

    Please read Using a Component in Your Application. Pay attention to single and multiple inheritance approaches. The direct approach is pretty inflexible and not suggested.
    J-P Nurmi

  3. #3
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    And what should I type:
    Qt Code:
    1. #include "ui_Maker.h"
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QDialog *window = new QDialog;
    7. Ui::ImageDialog ui; // what should I type here, because ImageDialog is an example??
    8. ui.setupUi(MainWindow); // here I renamed window to MainWindow
    9.  
    10. MainWindow->show(); // here I renamed window to MainWindow
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    And is anything correct in this main.cpp? Regards
    Last edited by wysota; 12th May 2007 at 23:37. Reason: Changed [qtclass] to [code]

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem displaying my main window

    This is the "direct approach" which was suggested against using. But oh well, here goes:
    Qt Code:
    1. #include "ui_Maker.h"
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QMainWindow *window = new QMainWindow; // create a main window, that's what you have designed
    7. Ui::MainWindow ui;
    8. ui.setupUi(window);
    9. window->show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    PS. Please use the "#"-button for highlighting code blocks.
    J-P Nurmi

  5. #5
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    Ok, so I have done it, but in compiling it, there appear error:

    collect2: ld returned 1 exit status
    make[1]: *** [release\Test.exe] Error 1
    make[1]: Leaving directory `C:/Qt/4.2.3/Qt'
    make: *** [release] Error 2

    What is wrong?
    Regards

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem displaying my main window

    What does the .pro file look like? What's the first error?
    J-P Nurmi

  7. #7
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    This is the .pro file
    Qt Code:
    1. CONFIG += qt
    2. HEADERS += ui_Maker.h
    3. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 
    And this is what appear in console. There are really many errors such as:
    in main.cpp - undefined reference to...
    and the first error is [release\test.exe] error 1
    and second is
    [release] error 2

    So what's wrong?
    Kind regards

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem displaying my main window

    Quote Originally Posted by Salazaar View Post
    This is the .pro file
    Qt Code:
    1. CONFIG += qt
    2. HEADERS += ui_Maker.h
    3. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 
    Please follow the directions I already gave you once. There is no need to generate the header and include it to the project by hand. You should be using a variable FORMS instead.

    Edit: Clean up the folder. Leave only files main.cpp and Maker.ui. Run "qmake -project" and you'll get a proper project file.

    And this is what appear in console. There are really many errors such as:
    in main.cpp - undefined reference to...
    and the first error is [release\test.exe] error 1
    and second is
    [release] error 2
    Well, you managed to cut the interesting part off. "error 1" or "error 2" does not tell anything valuable. Please paste all the errors including the undefined reference.
    J-P Nurmi

  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: Problem displaying my main window

    Maybe he should paste only the first few?

    And remember about closing the memory leak when you come to this point

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem displaying my main window

    Quote Originally Posted by wysota View Post
    Maybe he should paste only the first few?
    That's what I asked in the first place but it didn't work so I tried another approach..

    And remember about closing the memory leak when you come to this point
    First of all, I tried to advise against using the direct approach. Anyway, the same leak is also in the example..
    J-P Nurmi

  11. #11
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    Quote Originally Posted by jpn View Post
    Please follow the directions I already gave you once. There is no need to generate the header and include it to the project by hand. You should be using a variable FORMS instead.
    But if I want to make changes in the maker file, which I can't do in Designer such as connecting tools->sort to another dialog, I have to generate header file and make changes and add it to project by hand. Is that right?
    EDIT:
    I have generated project file by makefile but there appear the same errors such as:
    in main.cpp - undefined reference to _imp__ZN7QString4freeEPNS
    What is wrong?
    EDIT:
    I think this is problem with my Qt installation, because when I try to compile simple application lioke this:
    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. QPushButton hello("Hello world!");
    9. hello.resize(100, 30);
    10.  
    11. hello.show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    There appear errors such as undefined reference to QApplication, QPushButton and the same as in compiling converted ui file
    So, I'll ask once again. What's wrong? I have installed Qt to my mingw compiler, set 3 environment variables. I have done it with Marcel's help, so everything should be set.....
    Regards
    EDIT:
    Oh, now everything's ok, I just forgot to include QApplication to main file
    Last edited by wysota; 13th May 2007 at 15:41. Reason: Changed [qtclass] into [code]

  12. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem displaying my main window

    Quote Originally Posted by Salazaar View Post
    But if I want to make changes in the maker file, which I can't do in Designer such as connecting tools->sort to another dialog, I have to generate header file and make changes and add it to project by hand. Is that right?
    As the generated header says in the header comment, do never edit them by hand. Your changes will be lost if you ever want do adjust the designed form and the header is generated again. Use either single inheritance or multiple inheritance approach and do the changes in the actual widget/dialog/window class (which loads the designed form).
    J-P Nurmi

  13. #13
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    I really don't understand what is described in this link.

  14. #14
    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: Problem displaying my main window

    Please use the "code" tag (# button) instead of "qtclass" (Qt button) when pasting code.

  15. #15
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    So how can I connect other dialogs to my main windows action (it is all done with Qt Designer)

  16. #16
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem displaying my main window

    J-P Nurmi

  17. #17
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    Ok, thanks, I'll try it. But if I want to make things, which I can't do in Designer, so how can I make these changes without changing code?

  18. #18
    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: Problem displaying my main window

    Look again at the links JP gave you in post #12.

  19. #19
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    Hi. I tried to do what's described in http://www.qtcentre.org/forum/faq.ph...esigner_2forms
    but I don't know how to do it. I'd be veery thankful if somebody will do it on my code and add comments in the parts of code which were changed:

    Dialog file which I want to connect to actionAbout http://www.insidetennis.yoyo.pl/ui_About.txt

    And my main window
    http://www.insidetennis.yoyo.pl/ui_MainWindow.txt (Attention! The file is called ui_maker.h, not ui_mainwindow.h !!!)

    if someone can do it, I'd be very thankful...

  20. #20
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem displaying my main window

    Please, consider going through the nice tutorials shipped with Qt, starting from Qt Tutorial 1 - Hello World. We are not here to teach you the basics but to help you with problems you may encounter.
    J-P Nurmi

Similar Threads

  1. Replies: 15
    Last Post: 23rd March 2007, 17:16
  2. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 09:41
  3. Problem in porting Main window on linux
    By jyoti kumar in forum Qt Tools
    Replies: 2
    Last Post: 2nd June 2006, 09:35
  4. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 11:21
  5. Main window
    By Michiel in forum Qt Tools
    Replies: 1
    Last Post: 21st March 2006, 00:54

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.