Qt5 creating a QAction that calls an info window

1

I'm developing a solution in qt5.4.2, in my menu bar, when clicking an option, a new window should open with that information.

I was thinking of doing a QDialog , but depending on it would be complicated to edit some things and put images, for example. Then I created ui 's that will be called by these actions triggered by the triggered sign.

But I can not get the calling window open when the signal is triggered.

I imported the .h library of the window I want to call, in this case the aboutMain . I created an object from it (a new window) and now I want to show it.

Is this the way?

brprint.h - > .h main

#include <QMainWindow>
#include "loading.h"

namespace Ui {
class BrPrint3D;
}

class BrPrint3D : public QMainWindow
{
    Q_OBJECT

public:
    explicit BrPrint3D(QWidget *parent = 0);
    ~BrPrint3D();
    void init();

private slots:    
    void on_actionSobre_BrPrint3D_triggered();

private:
    Ui::BrPrint3D *ui;

};

brprint3d.cpp

#include "brprint3d.h"
#include "ui_Pandora.h"
#include "aboutbrprint.h"
#include <stdio.h>

//Sobre->Sobre o BrPrint3D
void BrPrint3D::on_actionSobre_BrPrint3D_triggered()
{
    //Chamar Janela Sobre o BrPrint
    aboutBrPrint window;
    window.show();


}

aboutBrPrint.h

#include <QWidget>

namespace Ui {
class aboutBrPrint;
}

class aboutBrPrint : public QWidget
{
    Q_OBJECT

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

private:
    Ui::aboutBrPrint *ui;
};

Main

#include "brprint3d.h"
#include <QApplication>
#include "loading.h"
#include <QTranslator>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    BrPrint3D w;
    w.show();
    w.init();
    return app.exec();
}
    
asked by anonymous 14.06.2015 / 16:58

1 answer

1

I believe that it is necessary to use new , because the first generated window is already bound to QApplication , new windows should receive this to be linked to each other, then the correct one would be this: / p>

void BrPrint3D::on_actionSobre_BrPrint3D_triggered()
{
    aboutBrPrint *window = new aboutBrPrint(this);
    window->show();
}

In case exec can also work (note that this will probably block the "parent" window while it is open), because exec can refer to the "parent" window, to unlock the parent window simply close the aboutBrPrint:

void BrPrint3D::on_actionSobre_BrPrint3D_triggered()
{
    aboutBrPrint window;
    window.exec();
}

In main.cpp we do not use the new constructor because the first window is already bound to the QOBJECT (I believe) that gets connected to the application, so new is not in "disuse", enjoy and read this link When should I choose whether to use a pointer when creating an object?

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    BrPrint3D w;
    w.show();
    w.init();
    return app.exec();
}
    
14.06.2015 / 23:47