PDA

View Full Version : QLabel| Pixmap Delay



vProgramm
29th January 2015, 17:32
Hello, i created a clickable labels in pixmap, but delay has occurred to open form. Code bellow:


#include "secdialog.h"
#include "ui_secdialog.h"
#include <QPixmap>


SecDialog::SecDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SecDialog)
{
ui->setupUi(this);


QPixmap pix("C:\\Users\\Edilson\\Documents\\Menu_Inicio\\Imagen s\\PratosQuentes.jpg");
ui->label_2->setPixmap(pix);

QPixmap pix2("C:\\Users\\Edilson\\Documents\\Menu_Inicio\\Imagen s\\PratosFrios.jpg");
ui->label_3->setPixmap(pix2);

QPixmap pix3("C:\\Users\\Edilson\\Documents\\Menu_Inicio\\Imagen s\\porcoes.jpg");
ui->label_4->setPixmap(pix3);

QPixmap pix4("C:\\Users\\Edilson\\Documents\\Menu_Inicio\\Imagen s\\Pizzas.jpg");
ui->label_5->setPixmap(pix4);

QPixmap pix5("C:\\Users\\Edilson\\Documents\\Menu_Inicio\\Imagen s\\Lanches.jpg");
ui->label_6->setPixmap(pix5);

QPixmap pix6("C:\\Users\\Edilson\\Documents\\Menu_Inicio\\Imagen s\\Bebidas.jpg");
ui->label_7->setPixmap(pix6);
}

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

ChrisW67
29th January 2015, 20:14
Nothing in the code you presented opens a form. Assuming this is the dialog you wish to display then its constructor looks OK (except for hard coded paths). There may be some time required to open and load (and probably scale) the image files (how big are they?) but it is incurred at object construction time,, not when you call show() or exec().

Perhaps you could provide some information about the "Delay has occurred to open form", where you notice the delay, how you have measured it, and what you have done to isolate it.

vProgramm
29th January 2015, 20:30
Sorry brah.

Code bellow:


void MainWindow::on_pushButton_2_clicked()
{
this->close();//Close the mainwindow and open the SecDialog
SecDialog dialog(this);
dialog.exec();
}

d_stranz
30th January 2015, 01:45
this->close();//Close the mainwindow and open the SecDialog

Ummm, if your intention is to hide the MainWindow, then you do not do this. In general, if you call the close() slot on the MainWindow and it is the only window visible for the app (which it probably is, since the dialog is not visible yet), the app will try to shut down. See QApplication::quitOnLastWindowClosed() - the default for this is true.

If you want to hide the main window when the dialog is shown, then call hide(), not close(). This might be the cause of your delay problem, I don't know. All I know is that you have probably shut down the main window's event loop when you call close(), and the only thing that is keeping the app running is the fact that the dialog has it's own temporary event loop running.

What are you going to do once the user closes the dialog? If you use hide(), your main window will be gone, the dialog is gone, but your app is still running with no way to make it visible again.