PDA

View Full Version : New form (ui) .problem :/



giannis1991
21st August 2015, 08:50
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) ...



browser bowser1;
browser1.show();



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 ! :/:(

anda_skoa
21st August 2015, 10:25
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,
_

giannis1991
21st August 2015, 11:08
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


#ifndef BROWSER_H
#define BROWSER_H

#include <QWidget>

namespace Ui {
class browser;
}

class browser : public QWidget
{
Q_OBJECT

public:
explicit browser(QWidget *parent = 0);
~browser();

private slots:


void on_pushButton_clicked();

void on_pushButton_2_clicked();

void on_pushButton_4_clicked();

void on_pushButton_3_clicked();

void on_lineEdit_textEdited(const QString &arg1);

void on_webView_destroyed();

void on_browser_accepted();

private:
Ui::browser *ui;
};

#endif // BROWSER_H




browser.cpp


#include "browser.h"
#include "ui_browser.h"

browser::browser(QWidget *parent) :
QWidget(parent),
ui(new Ui::browser)
{
// ui->setupUi(this);
}

browser::~browser()
{
delete ui;
}

void browser::on_pushButton_clicked()
{

}

void browser::on_pushButton_2_clicked()
{

}

void browser::on_pushButton_4_clicked()
{

}

void browser::on_pushButton_3_clicked()
{

}

void browser::on_lineEdit_textEdited(const QString &arg1)
{

}

void browser::on_webView_destroyed()
{

}

void browser::on_browser_accepted()
{

}


In mainwindow.h i added this


private:
Ui::MainWindow *ui;
browser browser1;
};

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



browser1.show();


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

anda_skoa
21st August 2015, 13:13
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,
_

giannis1991
21st August 2015, 13:45
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 :)

anda_skoa
21st August 2015, 14:50
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,
_

giannis1991
21st August 2015, 16:19
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

error: 'setupUi' was not declared in this scope

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

anda_skoa
21st August 2015, 17:22
Maybe you are calling it as


setupUi(this);

i.e. on the widget, instead of on the form object which has that method.

Cheers,
_

giannis1991
25th August 2015, 20:18
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 ok:)made my day :)