Results 1 to 9 of 9

Thread: New form (ui) .problem :/

  1. #1
    Join Date
    Aug 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default New form (ui) .problem :/

    Hello I am developing a new project and and it is the first for me with qt. I made a second form (ui) .I added some buttons and a qwebview then i added to a button of the mainwindow form a call to show the second form(browser.h) ...

    Qt Code:
    1. browser bowser1;
    2. browser1.show();
    To copy to clipboard, switch view to plain text mode 

    Button works normal and call the new form (browser.h)...But and this is the problem that the form which is called is empty! just a blank page without the widgets i added on ! :/

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: New form (ui) .problem :/

    First: it makes little sense to post code that is not the actual code.

    Second: is "browser" a class generated by QtCreator template (form class)? If not, did you correctly instantiate the UI class and call its setupUi() function?
    Does the form have proper layouting?

    Cheers,
    _

  3. #3
    Join Date
    Aug 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: New form (ui) .problem :/

    Quote Originally Posted by anda_skoa View Post
    First: it makes little sense to post code that is not the actual code.

    Second: is "browser" a class generated by QtCreator template (form class)? If not, did you correctly instantiate the UI class and call its setupUi() function?
    Does the form have proper layouting?

    Cheers,
    _
    Well i will give more info to sort it out

    browser.h

    Qt Code:
    1. #ifndef BROWSER_H
    2. #define BROWSER_H
    3.  
    4. #include <QWidget>
    5.  
    6. namespace Ui {
    7. class browser;
    8. }
    9.  
    10. class browser : public QWidget
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit browser(QWidget *parent = 0);
    16. ~browser();
    17.  
    18. private slots:
    19.  
    20.  
    21. void on_pushButton_clicked();
    22.  
    23. void on_pushButton_2_clicked();
    24.  
    25. void on_pushButton_4_clicked();
    26.  
    27. void on_pushButton_3_clicked();
    28.  
    29. void on_lineEdit_textEdited(const QString &arg1);
    30.  
    31. void on_webView_destroyed();
    32.  
    33. void on_browser_accepted();
    34.  
    35. private:
    36. Ui::browser *ui;
    37. };
    38.  
    39. #endif // BROWSER_H
    To copy to clipboard, switch view to plain text mode 



    browser.cpp

    Qt Code:
    1. #include "browser.h"
    2. #include "ui_browser.h"
    3.  
    4. browser::browser(QWidget *parent) :
    5. QWidget(parent),
    6. ui(new Ui::browser)
    7. {
    8. // ui->setupUi(this);
    9. }
    10.  
    11. browser::~browser()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void browser::on_pushButton_clicked()
    17. {
    18.  
    19. }
    20.  
    21. void browser::on_pushButton_2_clicked()
    22. {
    23.  
    24. }
    25.  
    26. void browser::on_pushButton_4_clicked()
    27. {
    28.  
    29. }
    30.  
    31. void browser::on_pushButton_3_clicked()
    32. {
    33.  
    34. }
    35.  
    36. void browser::on_lineEdit_textEdited(const QString &arg1)
    37. {
    38.  
    39. }
    40.  
    41. void browser::on_webView_destroyed()
    42. {
    43.  
    44. }
    45.  
    46. void browser::on_browser_accepted()
    47. {
    48.  
    49. }
    To copy to clipboard, switch view to plain text mode 

    In mainwindow.h i added this

    Qt Code:
    1. private:
    2. Ui::MainWindow *ui;
    3. browser browser1;
    4. };
    To copy to clipboard, switch view to plain text mode 

    and in "void" of the button which call the new form i added

    Qt Code:
    1. browser1.show();
    To copy to clipboard, switch view to plain text mode 

    The class generated by qt after i made the qt form(ui) called browser

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: New form (ui) .problem :/

    So the program does exactly what one expect it does.

    You have a widget without parent, so it becomes a top level window.
    The widget is empty, so the window is empty.

    Assuming you don't want it empty, allow it to use the form you have created.
    Just in case you didn't know: if you comment something out, it is not considered code by the compiler and not part of the functionality

    Cheers,
    _

  5. #5
    Join Date
    Aug 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: New form (ui) .problem :/

    thank you..its my first time with qt and i just started c++ ... i used a lot visual studio .net etc
    Of course i don't expect thecompiler to count comments as real code haha except if you decompile an application ...the decompiler can't realise the comments so it returns all comments as normal code

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: New form (ui) .problem :/

    Quote Originally Posted by giannis1991 View Post
    Of course i don't expect thecompiler to count comments as real code haha

    As I've already hinted in an earlier comment, the form's setupUi() method needs to be called.
    Because that's where the content is created.
    You have that inside a comment right now, so the widget stays empty.

    Cheers,
    _

  7. #7
    Join Date
    Aug 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: New form (ui) .problem :/

    I am really sorry i just realised what you said me previously...yeah i made this uisetup as comment ,because every time i am coding and compiler gives me errors i just make ita s comment and if i find a solution then i deleted it.. so now this call gave me error and after i saw your new message i tested it again

    with setupUi(this); i see this error
    Qt Code:
    1. error: 'setupUi' was not declared in this scope
    To copy to clipboard, switch view to plain text mode 

    i check .cpp and i have a declaration under private:

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: New form (ui) .problem :/

    Maybe you are calling it as
    Qt Code:
    1. setupUi(this);
    To copy to clipboard, switch view to plain text mode 
    i.e. on the widget, instead of on the form object which has that method.

    Cheers,
    _

  9. #9
    Join Date
    Aug 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: New form (ui) .problem :/

    Well,thank you a lot for all i just couldn't make it work :/ So i deleted my browser.h/browser.cpp/browser.ui ( i remembered that i had selected an empty form! ) so i thought it is a good idea to try the other one with the buttons! so i added a new with buttons .... i changed it to look like the previos browser.ui (qwebview,buttons etc) ..and voila!!! everything okmade my day

Similar Threads

  1. Pyqt Form Close Problem
    By revolrevol in forum Qt Programming
    Replies: 0
    Last Post: 3rd August 2015, 15:13
  2. Replies: 3
    Last Post: 18th July 2013, 04:12
  3. Form update problem
    By thefatladysingsopera in forum Newbie
    Replies: 9
    Last Post: 13th September 2011, 08:56
  4. Problem with .ui form
    By Fenix Voltres in forum Qt Tools
    Replies: 0
    Last Post: 14th September 2009, 17:37
  5. Form problem
    By dusza in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2009, 22:41

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.