dimanche 27 septembre 2015

Qt Widget not showing when using std::unique_ptr

I am trying to dynamically insert a new QLabel onto my main window. It works fine if I don't use std::unique_ptr and I can see the QLabel being drawn at my window. Why can't I use std::unique_ptr or std::shared_ptr?

MainWindow::MainWindow(QWidget *parent):QMainWindow(parent)
{

 setWindowFlags(Qt::FramelessWindowHint);
 ui.setupUi(this);

 std::unique_ptr<QLabel> shrd_QLabel = make_unique<QLabel>();
 shrd_QLabel->setParent(this);
 shrd_QLabel->setText("test");
 shrd_QLabel->setGeometry(70, 70, 70, 70);
 shrd_QLabel->show();
 //The above doesnt work, however, below example works perfectly

 QLabel * lpQLabel = new QLabel();
 lpQLabel->setParent(this);
 lpQLabel->setText("TEST #2");
 lpQLabel->setGeometry(70, 170, 70, 70);
 lpQLabel->show();
}

Aucun commentaire:

Enregistrer un commentaire