[Solved]Crash When show full screen
-
Hi all,
can someone explaim me why if i make this the application crash?
@MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
chiamaIMigliori();
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::chiamaIMigliori(){
IMigliori *schermataMIgliori = new IMigliori(); schermataMIgliori->showFullScreen();
}
@and Class "IMigliori"
@IMigliori::IMigliori(QWidget *parent) :
QWidget(parent),
ui(new Ui::IMigliori)
{
ui->setupUi(this);listaWidget *lista = new listaWidget(); this->layout()->addWidget(lista);
}
IMigliori::~IMigliori()
{
delete ui;
}
@why if i try to do this the app crash and if i set the follow code it run?
@MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
// chiamaIMigliori();listaWidget *lista = new listaWidget(); this->layout()->addWidget(lista);
}
MainWindow::~MainWindow()
{
delete ui;
}@the error is: @The program has unexpectedly finished.@
-
Does IMigliori have a valid layout set?
@
this->layout()->addWidget(lista); // crashes when there is no layout set
@
In addition, be aware that the IMigliore instance has no parent and the pointer is created on the stack and goes out of scope when MainWindow::chiamaIMigliori() is left - you will lose your only reference to the widget (there is QApplication::topLevelWidgets(), but it won't let you distinct between multiple IMigliore instances, as you have no object name set). -
[quote author="Lukas Geyer" date="1330584726"]Does IMigliori have a valid layout set?
@
this->layout()->addWidget(lista); // crashes when there is no layout set
@
In addition, be aware that the IMigliore instance has no parent and the pointer is created on the stack and goes out of scope when MainWindow::chiamaIMigliori() is left - you will lose your only reference to the widget (there is QApplication::topLevelWidgets(), but it won't let you distinct between multiple IMigliore instances, as you have no object name set).[/quote]so how i can solve this problem? with QLayout?
-
[quote author="Lukas Geyer" date="1330590798"]* Make sure you have selected a layout for your top-level widget in the designer.[/quote]
how I can do this? how a can select a layout from designer? I have to create a widget in the designer and then set my custom widget "listaWidget " same to ui widget?[quote author="Lukas Geyer" date="1330590798"]*Make schermataMIgliori a member of your class.[/quote]
how i can set schermataMIgliori member of mainWindow? -
[quote author="Vetryaspa" date="1330591900"]
how I can do this? how a can select a layout from designer? I have to create a widget in the designer
and then set my custom widget "listaWidget " same to ui widget?[/quote]
Make sure you have selected the top-level widget and <Rightclick> -> Layout and select the desired layout.[quote author="Vetryaspa" date="1330591900"]
how i can set schermataMIgliori member of mainWindow? [/quote]
@
class MainWindow : public QMainWindow
{
...
private:
IMigliori *schermataMIgliori;
}
@
[quote author="Vetryaspa" date="1330591900"]ok I have make some test and the main window don’t execute the[/quote]
Well, it's pretty hard to tell what's going wrong without showing any code. Provide an small, compilable example to get furher help.And if you want a honest answer: the source of your problems seems to be a lack of basic knowledge of C++, Qt and its tools. I would start with having a good read on these topics first.
-
ok i have understand that the problem is where i doing show of IMigliori because i have make this and the class was show:
@MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
// chiamaIMigliori();// schermataMIgliori = new IMigliori();
// schermataMIgliori->showFullScreen();
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::paintEvent(QPaintEvent *event){
qDebug()<< "PAINT EVENT MAINWINDOW";
schermataMIgliori = new IMigliori();
schermataMIgliori->showFullScreen();
}@now it was show();
i have try to found somting to creat and set a custom Widget class in a view but i not have found nothing to intrest me...
however now the window was call but if i set this:
@IMigliori::IMigliori(QWidget *parent) :
QWidget(parent),
ui(new Ui::IMigliori)
{
ui->setupUi(this);
}IMigliori::~IMigliori()
{
delete ui;
}void IMigliori::paintEvent(QPaintEvent *event){
qDebug()<< "PAINT EVENT IMIGLIORI";listaWidget *lista = new listaWidget(); this->layout()->addWidget(lista);
}
@the widget was not show... I have compere the XML ui of MainWindow with the IMigliori and i have see this row at the MainWindow
@ <layoutdefault spacing="6" margin="11"/>@
is possible to set somting like this in the other designer?
i have see all of standard layout but no one of this if for project. i need to be free to developer the app.... and using layout is not good.... so there is another way to set the widget in the class IMigliori? -
ok i have add the widget in LayoutBox like this:
@IMigliori::IMigliori(QWidget *parent) :
QWidget(parent),
ui(new Ui::IMigliori)
{
ui->setupUi(this);
lista = new listaWidget();
lista->setGeometry(QRect(0,100,360,400));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(lista);
setLayout(layout);
qDebug()<<lista->geometry();
}IMigliori::~IMigliori()
{
delete ui;
}void IMigliori::paintEvent(QPaintEvent *event){
qDebug()<< "PAINT EVENT IMIGLIORI";
qDebug()<<lista->geometry();
}
@but my problem now is the geometry of "listaWidget" because it paint a lis of object but the list occupies all screen and I wont it but i wont that respect a dimensione setted...
i have to modify a paintEvent in the "listaWidget" class?
-
Do yourself a favor and grab a good book on Qt and start reading it instead - they are even available "for free":http://www.qtrac.eu/marksummerfield.html - or at least take a look at the excellent "documentation":http://developer.qt.nokia.com/doc/qt-4.8/how-to-learn-qt.html that comes with Qt.
There is so much wrong with your code I honestly do not even know where to start; and even if I would I see no sense in it before you've gathered fundamental knowledge (this is no shame at all, we all started at this point somewhen), which is essential for doing any programming, with or without Qt.
-