Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to call an object created in another function.
Forum Updated to NodeBB v4.3 + New Features

How to call an object created in another function.

Scheduled Pinned Locked Moved Solved General and Desktop
c++function
17 Posts 2 Posters 5.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R ronyNS
    9 Aug 2016, 07:40

    Yes i am aware of that , but this is the problem https://forum.qt.io/topic/69999/how-to-add-a-label-on-a-layout-that-covers-the-entire-window/2
    This is the reason i am using resizeEvent.

    M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 9 Aug 2016, 07:45 last edited by
    #6

    @ronyNS
    ok :)
    Still not sure why layout wont work but resize event will then.
    You just want qLabel to cover all mainwindow ?

    1 Reply Last reply
    2
    • R Offline
      R Offline
      ronyNS
      wrote on 9 Aug 2016, 07:50 last edited by
      #7

      Yes , like i want to cover my login form , but when i drag the label on the ui it resizes according to the layout.
      I used size policy , but when i run it , the main window size is fixed and cannot be reduced.
      If there is an easy way , please tell me :)

      M 1 Reply Last reply 9 Aug 2016, 07:54
      0
      • R ronyNS
        9 Aug 2016, 07:50

        Yes , like i want to cover my login form , but when i drag the label on the ui it resizes according to the layout.
        I used size policy , but when i run it , the main window size is fixed and cannot be reduced.
        If there is an easy way , please tell me :)

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 9 Aug 2016, 07:54 last edited by
        #8

        @ronyNS
        ok, sounds like i dont understand the full setup then.
        Maybe resize event will just be easier :)

        1 Reply Last reply
        2
        • R Offline
          R Offline
          ronyNS
          wrote on 9 Aug 2016, 08:00 last edited by
          #9

          Yes , Thank you ! :)

          1 Reply Last reply
          1
          • R Offline
            R Offline
            ronyNS
            wrote on 9 Aug 2016, 14:21 last edited by
            #10

            Hey now i am getting 'Expected specifier before Qlabel' error . Please help

            M 1 Reply Last reply 9 Aug 2016, 14:31
            0
            • R ronyNS
              9 Aug 2016, 14:21

              Hey now i am getting 'Expected specifier before Qlabel' error . Please help

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 9 Aug 2016, 14:31 last edited by mrjj 8 Sept 2016, 14:32
              #11

              @ronyNS said:

              Expected

              show line where it says it :)

              did u include <QLabel>
              in mainwindow. h?

              if its for the line
              QLabel *lbl1;

              1 Reply Last reply
              0
              • R Offline
                R Offline
                ronyNS
                wrote on 9 Aug 2016, 14:50 last edited by
                #12
                void createlbl(){
                lbl1 = new QLabel("Hello");
                }
                

                Error is for this line only when i use lbl1 in other functions. Yes i have included Qlabel in .h file

                M 1 Reply Last reply 9 Aug 2016, 14:56
                0
                • R ronyNS
                  9 Aug 2016, 14:50
                  void createlbl(){
                  lbl1 = new QLabel("Hello");
                  }
                  

                  Error is for this line only when i use lbl1 in other functions. Yes i have included Qlabel in .h file

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 9 Aug 2016, 14:56 last edited by mrjj 8 Sept 2016, 14:57
                  #13

                  @ronyNS
                  well u are not in mainwindow method..

                  void XXXX::createlbl(){

                  XXXX should be mainwindow

                  when there is no NAME:: in front, its NOT a member function. just a plain function.

                  R 1 Reply Last reply 9 Aug 2016, 15:12
                  0
                  • M mrjj
                    9 Aug 2016, 14:56

                    @ronyNS
                    well u are not in mainwindow method..

                    void XXXX::createlbl(){

                    XXXX should be mainwindow

                    when there is no NAME:: in front, its NOT a member function. just a plain function.

                    R Offline
                    R Offline
                    ronyNS
                    wrote on 9 Aug 2016, 15:12 last edited by
                    #14

                    @mrjj
                    Still the same error

                    void MainWindow:: createlbl(){
                        lbl1 = new Qlabel();
                    }
                    

                    'expected type-specifier before QLabel

                    M 1 Reply Last reply 9 Aug 2016, 15:15
                    0
                    • R ronyNS
                      9 Aug 2016, 15:12

                      @mrjj
                      Still the same error

                      void MainWindow:: createlbl(){
                          lbl1 = new Qlabel();
                      }
                      

                      'expected type-specifier before QLabel

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 9 Aug 2016, 15:15 last edited by mrjj 8 Sept 2016, 15:18
                      #15

                      but it should work. ?

                      show mainwindow.h

                      here is sample that does so
                      https://www.dropbox.com/s/i0qj2e9mxbggymt/mylabel.zip?dl=0

                      1 Reply Last reply
                      2
                      • R Offline
                        R Offline
                        ronyNS
                        wrote on 9 Aug 2016, 15:57 last edited by
                        #16

                        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;
                        }
                        
                        
                        
                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 9 Aug 2016, 17:33 last edited by
                          #17

                          @ronyNS said:

                          lbl = new Qlabel();

                          misspelled ?
                          its QLabel ?

                          lbl = new QLabel();
                          big L ?

                          1 Reply Last reply
                          2

                          15/17

                          9 Aug 2016, 15:15

                          • Login

                          • Login or register to search.
                          15 out of 17
                          • First post
                            15/17
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved