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. namespace doubts in program
Forum Updated to NodeBB v4.3 + New Features

namespace doubts in program

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 3 Posters 4.3k 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.
  • mrjjM mrjj

    @o6a6r9v1p

    Well i just have a function in mainwindow. I call from constructor.
    But what i mean is , you can also have
    a button that then add new widgets to the interface.
    And so on.
    So use a function as not to make constructor big or directly on button / where u need it.

    O Offline
    O Offline
    o6a6r9v1p
    wrote on last edited by
    #10

    @mrjj
    I did as you told.

    The DemoApp Constructor is:
    @
    DemoApp::DemoApp(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::DemoApp)
    {
    ui->setupUi(this);

    modifyGui(this); //this function is added now
    
    
    connect(this, SIGNAL(----), ----, SLOT(-----));
    connect(-----, SIGNAL(----)), this, SLOT(----));
    

    }
    @

    @
    void modifyGui(QMainWindow *DemoApp)
    {

    --

    }
    @
    is defined in main.cpp

    I am getting the error : "modifyGui" was not declared in this scope
    where shall I put this function?

    jsulmJ 1 Reply Last reply
    0
    • O o6a6r9v1p

      @mrjj
      I did as you told.

      The DemoApp Constructor is:
      @
      DemoApp::DemoApp(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::DemoApp)
      {
      ui->setupUi(this);

      modifyGui(this); //this function is added now
      
      
      connect(this, SIGNAL(----), ----, SLOT(-----));
      connect(-----, SIGNAL(----)), this, SLOT(----));
      

      }
      @

      @
      void modifyGui(QMainWindow *DemoApp)
      {

      --

      }
      @
      is defined in main.cpp

      I am getting the error : "modifyGui" was not declared in this scope
      where shall I put this function?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #11

      @o6a6r9v1p Why is modifyGui in main.cpp?
      It must be a method in DemoApp as it is handling its content. Add modifyGui declaration to DemoApp class in demoapp.h and the definition to demoapp.cpp:

      void DemoApp::modifyGui()
      {
      ...
      }
      

      Also you do not need to pass any pointer to modifyGui if it is member of DemoApp.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      O 1 Reply Last reply
      1
      • jsulmJ jsulm

        @o6a6r9v1p Why is modifyGui in main.cpp?
        It must be a method in DemoApp as it is handling its content. Add modifyGui declaration to DemoApp class in demoapp.h and the definition to demoapp.cpp:

        void DemoApp::modifyGui()
        {
        ...
        }
        

        Also you do not need to pass any pointer to modifyGui if it is member of DemoApp.

        O Offline
        O Offline
        o6a6r9v1p
        wrote on last edited by
        #12

        @jsulm
        Did as you told. It is now compiling.

        when I added widgets, they are not visible in GUI. do i modify any property ( I used Label, linedit widgets)
        How to use other classes, for example, code from others etc. in my code. What precautions are to be taken

        mrjjM 1 Reply Last reply
        0
        • O o6a6r9v1p

          @jsulm
          Did as you told. It is now compiling.

          when I added widgets, they are not visible in GUI. do i modify any property ( I used Label, linedit widgets)
          How to use other classes, for example, code from others etc. in my code. What precautions are to be taken

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #13

          @o6a6r9v1p

          Hi after you create a new Widget (with parent)
          you might need to call show.

          Or it just a bug and you give it to wrong parent and its covered under something.

          So please show code on how you create and insert the new widgets.

          O 1 Reply Last reply
          0
          • mrjjM mrjj

            @o6a6r9v1p

            Hi after you create a new Widget (with parent)
            you might need to call show.

            Or it just a bug and you give it to wrong parent and its covered under something.

            So please show code on how you create and insert the new widgets.

            O Offline
            O Offline
            o6a6r9v1p
            wrote on last edited by
            #14

            @mrjj
            Code for ModifyGui() is
            @
            void DemoApp::modifyGui()
            {

            QLabel *label_Status1 = new QLabel(tr("Status1"));
            label_Status1->setObjectName(QString::fromUtf8("Status1"));
            label_Status1->setEnabled(true);
            label_Status1->setGeometry(QRect(410, 10, 41, 21));
            label_Status1->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
            QLineEdit *deviceStatus1 = new QLineEdit();
            deviceStatus1->setObjectName(QString::fromUtf8("deviceStatus1"));
            deviceStatus1->setEnabled(true);
            deviceStatus1->setGeometry(QRect(20, 10, 391, 20));
            deviceStatus1->setReadOnly(true);
            
            QHBoxLayout *statusLayout = new QHBoxLayout;
            statusLayout->addWidget(deviceStatus1);
            statusLayout->addWidget(label_Status1);
            
            QVBoxLayout *mainLayout = new QVBoxLayout;
            

            // mainLayout->addLayout(statusLayout);
            setLayout(mainLayout);

            setWindowTitle(tr(" Device Monitor"));
            

            }

            @

            when i uncomment the commented line, I am getting error
            "no matching function ".
            little confused with call sequence or format in Qt.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #15

              It seems you try to add layout to layout ?

              Make sure its the right type
              http://doc.qt.io/qt-5/qgridlayout.html#addLayout
              or
              http://doc.qt.io/qt-5/qboxlayout.html#addLayout
              or ?
              and to include the other parameters depending of the type of mainLayout

              Alternatively , use a place holder widget
              Apply statusLayout to this widget and
              mainLayout->addWidget(place_holder);

              1 Reply Last reply
              1
              • O Offline
                O Offline
                o6a6r9v1p
                wrote on last edited by
                #16

                Hi mrjj,
                This is the code for setupGui() & retranslate Gui()

                @
                void setupUi(QMainWindow *DemoApp)
                {
                if (DemoApp->objectName().isEmpty())
                DemoApp->setObjectName(QString::fromUtf8("DemoApp"));
                DemoApp->resize(600, 400);
                centralWidget = new QWidget(DemoApp);
                centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
                progressBar = new QProgressBar(centralWidget);
                progressBar->setObjectName(QString::fromUtf8("progressBar"));
                progressBar->setEnabled(false);
                progressBar->setGeometry(QRect(20, 100, 421, 21));
                progressBar->setMaximum(1024);
                progressBar->setValue(0);
                progressBar->setTextVisible(false);
                pushButton = new QPushButton(centralWidget);
                pushButton->setObjectName(QString::fromUtf8("pushButton"));
                pushButton->setEnabled(false);
                pushButton->setGeometry(QRect(20, 50, 91, 21));
                pushbuttonStatus = new QLabel(centralWidget);
                pushbuttonStatus->setObjectName(QString::fromUtf8("pushbuttonStatus"));
                pushbuttonStatus->setEnabled(false);
                pushbuttonStatus->setGeometry(QRect(200, 50, 231, 20));
                pushbuttonStatus->setCursor(QCursor(Qt::ArrowCursor));
                pushbuttonStatus->setInputMethodHints(Qt::ImhNone);
                pushbuttonStatus->setFrameShadow(QFrame::Plain);
                pushbuttonStatus->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
                label_2 = new QLabel(centralWidget);
                label_2->setObjectName(QString::fromUtf8("label_2"));
                label_2->setEnabled(false);
                label_2->setGeometry(QRect(30, 80, 401, 20));
                label_2->setAlignment(Qt::AlignCenter);
                label_3 = new QLabel(centralWidget);
                label_3->setObjectName(QString::fromUtf8("label_3"));
                label_3->setEnabled(true);
                label_3->setGeometry(QRect(410, 10, 41, 21));
                label_3->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
                deviceStatus = new QLineEdit(centralWidget);
                deviceStatus->setObjectName(QString::fromUtf8("deviceStatus"));
                deviceStatus->setEnabled(true);
                deviceStatus->setGeometry(QRect(20, 10, 391, 20));
                deviceStatus->setReadOnly(true);

                    DemoApp->setCentralWidget(centralWidget);
                    menuBar = new QMenuBar(DemoApp);
                    menuBar->setObjectName(QString::fromUtf8("menuBar"));
                    menuBar->setGeometry(QRect(0, 0, 461, 23));
                    DemoApp->setMenuBar(menuBar);
                    statusBar = new QStatusBar(DemoApp);
                    statusBar->setObjectName(QString::fromUtf8("statusBar"));
                    DemoApp->setStatusBar(statusBar);
                
                    retranslateUi(DemoApp);
                
                    QMetaObject::connectSlotsByName(DemoApp);
                } // setupUi
                

                @

                @ void retranslateUi(QMainWindow *DemoApp)
                {
                DemoApp->setWindowTitle(QApplication::translate("DemoApp", "DemoApp", 0));
                pushButton->setText(QApplication::translate("DemoApp", "ToggleLED(s)", 0));
                pushbuttonStatus->setText(QApplication::translate("DemoApp", "Pushbutton State: Pressed", 0));
                label_2->setText(QApplication::translate("DemoApp", "Not Pressed", 0));
                label_3->setText(QApplication::translate("DemoApp", "Status", 0));
                deviceStatus->setText(QApplication::translate("DemoApp", "Device Not Detected: Verify Connection/Correct Firmware", 0));
                } // retranslateUi
                @

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  o6a6r9v1p
                  wrote on last edited by
                  #17

                  Sorry Typing mistake. They are setupUi() and retranslateUi().

                  It means we have to add widgets to centralwindow.
                  thank you.

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    o6a6r9v1p
                    wrote on last edited by
                    #18

                    modifyGui() is changed as told by you.

                    @void DemoApp::modifyGui()
                    {

                    QLabel *label_Status1 = new QLabel(tr("Status1"));
                    label_Status1->setObjectName(QString::fromUtf8("Status1"));
                    label_Status1->setEnabled(true);
                    label_Status1->setGeometry(QRect(410, 10, 41, 21));
                    label_Status1->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
                    QLineEdit *deviceStatus1 = new QLineEdit();
                    deviceStatus1->setObjectName(QString::fromUtf8("deviceStatus1"));
                    deviceStatus1->setEnabled(true);
                    deviceStatus1->setGeometry(QRect(20, 10, 391, 20));
                    deviceStatus1->setReadOnly(true);
                    
                    QHBoxLayout *statusLayout = new QHBoxLayout;
                    statusLayout->addWidget(deviceStatus1);
                    statusLayout->addWidget(label_Status1);
                    

                    QWidget *window = new QWidget();
                    window->setLayout(statusLayout);
                    setCentralWidget(window);

                    }
                    @

                    It is showing GUI, but it stops working,
                    it gives the message "The program has unexpectedly finished."
                    what may be the problem?

                    mrjjM 1 Reply Last reply
                    0
                    • O o6a6r9v1p

                      modifyGui() is changed as told by you.

                      @void DemoApp::modifyGui()
                      {

                      QLabel *label_Status1 = new QLabel(tr("Status1"));
                      label_Status1->setObjectName(QString::fromUtf8("Status1"));
                      label_Status1->setEnabled(true);
                      label_Status1->setGeometry(QRect(410, 10, 41, 21));
                      label_Status1->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
                      QLineEdit *deviceStatus1 = new QLineEdit();
                      deviceStatus1->setObjectName(QString::fromUtf8("deviceStatus1"));
                      deviceStatus1->setEnabled(true);
                      deviceStatus1->setGeometry(QRect(20, 10, 391, 20));
                      deviceStatus1->setReadOnly(true);
                      
                      QHBoxLayout *statusLayout = new QHBoxLayout;
                      statusLayout->addWidget(deviceStatus1);
                      statusLayout->addWidget(label_Status1);
                      

                      QWidget *window = new QWidget();
                      window->setLayout(statusLayout);
                      setCentralWidget(window);

                      }
                      @

                      It is showing GUI, but it stops working,
                      it gives the message "The program has unexpectedly finished."
                      what may be the problem?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #19

                      @o6a6r9v1p said in namespace doubts in program:

                      "The program has unexpectedly finished."

                      It means it crash.
                      Fastest way is to set some breakpoints and
                      single step between them to try find the line that makes crash.

                      Nothing springs to eye for crashing in that code.

                      O 1 Reply Last reply
                      1
                      • mrjjM mrjj

                        @o6a6r9v1p said in namespace doubts in program:

                        "The program has unexpectedly finished."

                        It means it crash.
                        Fastest way is to set some breakpoints and
                        single step between them to try find the line that makes crash.

                        Nothing springs to eye for crashing in that code.

                        O Offline
                        O Offline
                        o6a6r9v1p
                        wrote on last edited by
                        #20

                        @mrjj
                        Thanks to all for pointing in right direction.

                        1 Reply Last reply
                        0

                        • Login

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