How to call an object created in another function.
Solved
General and Desktop
-
-
but it should work. ?
show mainwindow.h
here is sample that does so
https://www.dropbox.com/s/i0qj2e9mxbggymt/mylabel.zip?dl=0 -
my mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include<QLabel> #include <QMainWindow> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); QLabel *lbl; protected: void resizeEvent(QResizeEvent *evt) override; private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
my mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include<QLabel> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } void MainWindow:: createlbl(){ lbl = new Qlabel(); } void MainWindow :: resizeEvent(QResizeEvent *evt) { MainWindow::setCentralWidget(lbl); lbl->setStyleSheet("Background-color:pink"); QMainWindow::resizeEvent(evt); //call base implementation } MainWindow::~MainWindow() { delete ui; }