Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Added widgets manually to Qt generated code, shown in 2nd window
Qt 6.12 LTS is out! See what's new in the release blog

Added widgets manually to Qt generated code, shown in 2nd window

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 5 Posters 4.8k 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.
  • J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on last edited by
    #8

    "label_Status" is missing"

    label_Status is empty, it has neither a picture nor a text and is set to a white or transparent background by default.

    add

    label_Status->setStyleSheet("background-color:red;");
    

    and you'll see a red line where your QLabel is in the layout.


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    1 Reply Last reply
    3
    • jsulmJ jsulm

      @o6a6r9v1p

      QWidget *w = new QWidget(this);
      

      but you still have to add it to a layout in your DemoApp.

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

      @jsulm said in Added widgets manually to Qt generated code, shown in 2nd window:

      @o6a6r9v1p

      QWidget *w = new QWidget(this);
      

      but you still have to add it to a layout in your DemoApp.

      Main GUI is simple with a pushbutton and Line edit. There is no layout in it. Then how to add w to a layout.

      jsulmJ 1 Reply Last reply
      0
      • O o6a6r9v1p

        @jsulm said in Added widgets manually to Qt generated code, shown in 2nd window:

        @o6a6r9v1p

        QWidget *w = new QWidget(this);
        

        but you still have to add it to a layout in your DemoApp.

        Main GUI is simple with a pushbutton and Line edit. There is no layout in it. Then how to add w to a layout.

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

        @o6a6r9v1p First, add a layout to MainGui (in designer), then add your widget to that layout (you can get it using http://doc.qt.io/qt-5/qwidget.html#layout).

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

        O 1 Reply Last reply
        2
        • jsulmJ jsulm

          @o6a6r9v1p First, add a layout to MainGui (in designer), then add your widget to that layout (you can get it using http://doc.qt.io/qt-5/qwidget.html#layout).

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

          @jsulm
          Now i am getting only Main window, it seems the added/new widgets are not shown.

          when i added layout to existing/old widgets , declared in ui_*.h, program is crashing.

          jsulmJ 1 Reply Last reply
          0
          • O o6a6r9v1p

            @jsulm
            Now i am getting only Main window, it seems the added/new widgets are not shown.

            when i added layout to existing/old widgets , declared in ui_*.h, program is crashing.

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

            @o6a6r9v1p You should add the layout in designer. Can you show the code? Just saying it is crashing does not help to solve the problem.

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

            O 1 Reply Last reply
            1
            • jsulmJ jsulm

              @o6a6r9v1p You should add the layout in designer. Can you show the code? Just saying it is crashing does not help to solve the problem.

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

              @jsulm
              added layout in designer, code is changed.
              Code snippets are given below:
              @

              QT_BEGIN_NAMESPACE

              class Ui_DemoApp
              {
              public:
              QWidget *centralWidget;
              QProgressBar *progressBar;
              QPushButton *pushButton;
              QLabel *label_3;
              QLineEdit *deviceStatus;
              QMenuBar *menuBar;
              QStatusBar *statusBar;
              QHBoxLayout *horizontalLayout;
              QHBoxLayout *horizontalLayout_2;
              QHBoxLayout *horizontalLayout_3;
              QHBoxLayout *horizontalLayout_4;
              QVBoxLayout *verticalLayout;
              QSpacerItem *horinzontalspacer;

              void setupUi(QMainWindow *DemoApp)
              {
                  if (DemoApp->objectName().isEmpty())
                      DemoApp->setObjectName(QString::fromUtf8("DemoApp"));
                  DemoApp->resize(461, 165);
                  centralWidget = new QWidget(DemoApp);
                  centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
                  pushButton = new QPushButton(centralWidget);
                  pushButton->setObjectName(QString::fromUtf8("pushButton"));
                  pushButton->setEnabled(false);
                  pushButton->setGeometry(QRect(20, 50, 91, 21));
                  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);
              

              /*
              with the following commented lines, program crashes
              */
              // horizontalLayout->addWidget(deviceStatus);
              // horizontalLayout->addWidget(label_3);

              // horizontalLayout_2->addWidget(pushButton);
              // horizontalLayout_2->addWidget(horinzontalspacer);

              // verticalLayout->addLayout(horizontalLayout);
              // verticalLayout->addLayout(horizontalLayout_2);

                  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", "PushOn", 0));
                  label_3->setText(QApplication::translate("DemoApp", "Status", 0));
                  deviceStatus->setText(QApplication::translate("DemoApp", "Device Not Detected", 0));
              } // retranslateUi
              

              };

              namespace Ui {
              class DemoApp: public Ui_DemoApp {};
              } // namespace Ui

              QT_END_NAMESPACE

              #endif // UI_DEMOAPP_H
              @

              @
              DemoApp::DemoApp(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::DemoApp)
              {
              ui->setupUi(this);
              extendGui(this);
              }
              @

              @
              void DemoApp::extendGui(QWidget *parent)
              {

              QLabel *label_Status = new QLabel("Staus");
              label_Status->setObjectName(QString::fromUtf8("Stat3"));
              label_Status->setEnabled(true);
              label_Status->setGeometry(QRect(410, 10, 41, 21));
              label_Status->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
              QLineEdit *deviceStatus1 = new QLineEdit("Device Status");
              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_Status);
              
              
              QVBoxLayout *mainLayout = new QVBoxLayout;
                  // mainLayout->addWidget(statusLayout);
                  //mainLayout->addLayout(titleLayout);
              
                  mainLayout->addLayout(statusLayout);  
                      QWidget *w = new QWidget(this);
                      w->setLayout(mainLayout); 
                      w->setWindowTitle("layouts");
              
                      w->show();
              

              // verticallayout->addLayout(w);
              //ui->centralWidget->layout()->addWidget(mainLayout);

              }

              @

              1 Reply Last reply
              0
              • J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #14
                /*
                with the following commented lines, program crashes
                */
                // horizontalLayout->addWidget(deviceStatus);
                // horizontalLayout->addWidget(label_3);
                
                // horizontalLayout_2->addWidget(pushButton);
                // horizontalLayout_2->addWidget(horinzontalspacer);
                
                // verticalLayout->addLayout(horizontalLayout);
                // verticalLayout->addLayout(horizontalLayout_2);
                

                You define horizontalLayout, horizontalLayout_2 and verticalLayout as pointers, but they don't point to an object. THis causes the crash.

                try

                horizontalLayout = new QHBoxLayout();
                

                and you can add widgets to the Layout. in your special case here:

                centralWidget = new QWidget(DemoApp);
                    centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
                    pushButton = new QPushButton();
                    ...
                    label_3 = new QLabel();
                    ...
                    deviceStatus = new QLineEdit(centralWidget);
                    ...
                
                
                    QHBoxLayout *horizontalLayout = new QHBoxLayout();
                    horizontalLayout->addWidget(pushButton);
                    horizontalLayout->addWidget(label_3);
                    horizontalLayout->addWidget(deviceStatus);
                    centralWidget->setLayout(horizontalLayout);
                

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                O 1 Reply Last reply
                1
                • J.HilkJ J.Hilk
                  /*
                  with the following commented lines, program crashes
                  */
                  // horizontalLayout->addWidget(deviceStatus);
                  // horizontalLayout->addWidget(label_3);
                  
                  // horizontalLayout_2->addWidget(pushButton);
                  // horizontalLayout_2->addWidget(horinzontalspacer);
                  
                  // verticalLayout->addLayout(horizontalLayout);
                  // verticalLayout->addLayout(horizontalLayout_2);
                  

                  You define horizontalLayout, horizontalLayout_2 and verticalLayout as pointers, but they don't point to an object. THis causes the crash.

                  try

                  horizontalLayout = new QHBoxLayout();
                  

                  and you can add widgets to the Layout. in your special case here:

                  centralWidget = new QWidget(DemoApp);
                      centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
                      pushButton = new QPushButton();
                      ...
                      label_3 = new QLabel();
                      ...
                      deviceStatus = new QLineEdit(centralWidget);
                      ...
                  
                  
                      QHBoxLayout *horizontalLayout = new QHBoxLayout();
                      horizontalLayout->addWidget(pushButton);
                      horizontalLayout->addWidget(label_3);
                      horizontalLayout->addWidget(deviceStatus);
                      centralWidget->setLayout(horizontalLayout);
                  
                  O Offline
                  O Offline
                  o6a6r9v1p
                  wrote on last edited by
                  #15

                  @J.Hilk
                  I rewrote the entire program avoiding Qtcreator, to extend that later on.
                  the program is:

                  @
                  //main.cpp
                  #include <QApplication>
                  #include <QPushButton>
                  #include <QHBoxLayout>
                  #include <QVBoxLayout>
                  #include <QWidget>
                  #include "demoapp.h"

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

                  DemoApp w;
                  w.show();
                  return app.exec();
                  

                  }
                  @

                  @
                  //demoapp.h
                  #ifndef DEMOAPP_H
                  #define DEMOAPP_H

                  #include <QMainWindow>

                  #include <QProgressBar>
                  #include <QLabel>
                  #include <QLineEdit>
                  #include <QHBoxLayout>
                  #include <QPushButton>

                  class QLineEdit;

                  class DemoApp : public QMainWindow
                  {
                  Q_OBJECT

                  public:
                  explicit DemoApp(QWidget *parent = 0);
                  ~DemoApp();
                  public:
                  QWidget *centralWidget;
                  QProgressBar *progressBar;
                  QPushButton *pushButton;
                  QLabel *pushbuttonStatus;
                  QLabel *label_2;
                  QLabel *label_3;
                  QLineEdit *deviceStatus;
                  QMenuBar *menuBar;
                  QStatusBar *statusBar;
                  QHBoxLayout *horizontalLayout;
                  QHBoxLayout *horizontalLayout_2;
                  QHBoxLayout *horizontalLayout_3;
                  QHBoxLayout *horizontalLayout_4;
                  QVBoxLayout *verticalLayout;
                  QSpacerItem *horinzontalspacer;

                  private:
                  void setupUi();
                  public slots:
                  void update_gui(bool Connected, bool isPressed, int Value);

                  signals:
                  void pushButton_pressed();

                  private slots:
                  void on_pushButton_clicked();
                  };

                  #endif // DEMOAPP_H
                  @

                  @
                  //demoapp.cpp
                  #include "demoapp.h"

                  #include <QLabel>
                  #include <QLineEdit>
                  #include <QHBoxLayout>
                  #include <QVBoxLayout>
                  #include <QWidget>

                  DemoApp::DemoApp(QWidget *parent) :
                  QMainWindow(parent)
                  {
                  progressBar = new QProgressBar(this);
                  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(this);
                  pushButton->setObjectName(QString::fromUtf8("pushButton"));
                  pushButton->setEnabled(false);
                  pushButton->setGeometry(QRect(20, 50, 91, 21));
                  pushbuttonStatus = new QLabel(this);
                  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(this);
                  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(this);
                  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);

                  QHBoxLayout *horizontalLayout = new QHBoxLayout();
                  horizontalLayout->addWidget(deviceStatus);
                  horizontalLayout->addWidget(label_3);
                  
                  QHBoxLayout *horizontalLayout1 = new QHBoxLayout();
                  horizontalLayout1->addWidget(pushButton);
                  horizontalLayout1->addWidget(pushbuttonStatus);
                  
                  QVBoxLayout *verticalLayout = new QVBoxLayout();
                  
                  verticalLayout->addLayout(horizontalLayout);
                  verticalLayout->addLayout(horizontalLayout1);
                  verticalLayout->addWidget(label_2);
                  verticalLayout->addWidget(progressBar);
                  setLayout(verticalLayout);
                  setWindowTitle(tr("Device Monitor"));
                  

                  //setupUi();
                  }

                  DemoApp::~DemoApp()
                  {
                  }

                  void DemoApp::setupUi()
                  {
                  ;
                  }

                  void DemoApp::on_pushButton_clicked()
                  {
                  emit pushButton_pressed();
                  }

                  void DemoApp::update_gui(bool Connected, bool isPressed, int Value)
                  {
                  if(Connected)
                  {
                  label_2->setEnabled(true);
                  pushButton->setEnabled(true);
                  pushbuttonStatus->setEnabled(true);
                  progressBar->setEnabled(true);

                      deviceStatus->setText("Device Connected");
                  
                      if(isPressed)
                          pushbuttonStatus->setText("Pushbutton : Pressed");
                      else
                          pushbuttonStatus->setText("Pushbutton : Not Pressed");
                  
                      progressBar->setValue(Value);
                  }
                  else
                  {
                      label_2->setEnabled(false);
                      pushButton->setEnabled(false);
                      pushbuttonStatus->setEnabled(false);
                      progressBar->setEnabled(false);
                      deviceStatus->setText("Device Not connected");
                      pushbuttonStatus->setText("Pushbutton : Unknown");
                      progressBar->setValue(0);
                  }
                  

                  }
                  @

                  when it is run it gives following message:
                  QObject::setParent: Cannot set parent, new parent is in a different thread
                  The program has unexpectedly finished.

                  I did not get where exactly problem is.

                  O 1 Reply Last reply
                  0
                  • O o6a6r9v1p

                    @J.Hilk
                    I rewrote the entire program avoiding Qtcreator, to extend that later on.
                    the program is:

                    @
                    //main.cpp
                    #include <QApplication>
                    #include <QPushButton>
                    #include <QHBoxLayout>
                    #include <QVBoxLayout>
                    #include <QWidget>
                    #include "demoapp.h"

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

                    DemoApp w;
                    w.show();
                    return app.exec();
                    

                    }
                    @

                    @
                    //demoapp.h
                    #ifndef DEMOAPP_H
                    #define DEMOAPP_H

                    #include <QMainWindow>

                    #include <QProgressBar>
                    #include <QLabel>
                    #include <QLineEdit>
                    #include <QHBoxLayout>
                    #include <QPushButton>

                    class QLineEdit;

                    class DemoApp : public QMainWindow
                    {
                    Q_OBJECT

                    public:
                    explicit DemoApp(QWidget *parent = 0);
                    ~DemoApp();
                    public:
                    QWidget *centralWidget;
                    QProgressBar *progressBar;
                    QPushButton *pushButton;
                    QLabel *pushbuttonStatus;
                    QLabel *label_2;
                    QLabel *label_3;
                    QLineEdit *deviceStatus;
                    QMenuBar *menuBar;
                    QStatusBar *statusBar;
                    QHBoxLayout *horizontalLayout;
                    QHBoxLayout *horizontalLayout_2;
                    QHBoxLayout *horizontalLayout_3;
                    QHBoxLayout *horizontalLayout_4;
                    QVBoxLayout *verticalLayout;
                    QSpacerItem *horinzontalspacer;

                    private:
                    void setupUi();
                    public slots:
                    void update_gui(bool Connected, bool isPressed, int Value);

                    signals:
                    void pushButton_pressed();

                    private slots:
                    void on_pushButton_clicked();
                    };

                    #endif // DEMOAPP_H
                    @

                    @
                    //demoapp.cpp
                    #include "demoapp.h"

                    #include <QLabel>
                    #include <QLineEdit>
                    #include <QHBoxLayout>
                    #include <QVBoxLayout>
                    #include <QWidget>

                    DemoApp::DemoApp(QWidget *parent) :
                    QMainWindow(parent)
                    {
                    progressBar = new QProgressBar(this);
                    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(this);
                    pushButton->setObjectName(QString::fromUtf8("pushButton"));
                    pushButton->setEnabled(false);
                    pushButton->setGeometry(QRect(20, 50, 91, 21));
                    pushbuttonStatus = new QLabel(this);
                    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(this);
                    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(this);
                    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);

                    QHBoxLayout *horizontalLayout = new QHBoxLayout();
                    horizontalLayout->addWidget(deviceStatus);
                    horizontalLayout->addWidget(label_3);
                    
                    QHBoxLayout *horizontalLayout1 = new QHBoxLayout();
                    horizontalLayout1->addWidget(pushButton);
                    horizontalLayout1->addWidget(pushbuttonStatus);
                    
                    QVBoxLayout *verticalLayout = new QVBoxLayout();
                    
                    verticalLayout->addLayout(horizontalLayout);
                    verticalLayout->addLayout(horizontalLayout1);
                    verticalLayout->addWidget(label_2);
                    verticalLayout->addWidget(progressBar);
                    setLayout(verticalLayout);
                    setWindowTitle(tr("Device Monitor"));
                    

                    //setupUi();
                    }

                    DemoApp::~DemoApp()
                    {
                    }

                    void DemoApp::setupUi()
                    {
                    ;
                    }

                    void DemoApp::on_pushButton_clicked()
                    {
                    emit pushButton_pressed();
                    }

                    void DemoApp::update_gui(bool Connected, bool isPressed, int Value)
                    {
                    if(Connected)
                    {
                    label_2->setEnabled(true);
                    pushButton->setEnabled(true);
                    pushbuttonStatus->setEnabled(true);
                    progressBar->setEnabled(true);

                        deviceStatus->setText("Device Connected");
                    
                        if(isPressed)
                            pushbuttonStatus->setText("Pushbutton : Pressed");
                        else
                            pushbuttonStatus->setText("Pushbutton : Not Pressed");
                    
                        progressBar->setValue(Value);
                    }
                    else
                    {
                        label_2->setEnabled(false);
                        pushButton->setEnabled(false);
                        pushbuttonStatus->setEnabled(false);
                        progressBar->setEnabled(false);
                        deviceStatus->setText("Device Not connected");
                        pushbuttonStatus->setText("Pushbutton : Unknown");
                        progressBar->setValue(0);
                    }
                    

                    }
                    @

                    when it is run it gives following message:
                    QObject::setParent: Cannot set parent, new parent is in a different thread
                    The program has unexpectedly finished.

                    I did not get where exactly problem is.

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

                    @o6a6r9v1p
                    I have followed "Calculator" example code from Qt examples, while writing above application.

                    jsulmJ 1 Reply Last reply
                    0
                    • O o6a6r9v1p

                      @o6a6r9v1p
                      I have followed "Calculator" example code from Qt examples, while writing above application.

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

                      @o6a6r9v1p You're doing something wrong. In your class you declare variables for the layouts, but then in the constructor you define local variables with same names:

                      QHBoxLayout *horizontalLayout = new QHBoxLayout();
                      

                      Are you aware that this horizontalLayout is not the same you declared in your class? If you later try to access it your app will crash. Just do it like this in your constructor:

                      horizontalLayout = new QHBoxLayout();
                      

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

                      O 1 Reply Last reply
                      2
                      • jsulmJ jsulm

                        @o6a6r9v1p You're doing something wrong. In your class you declare variables for the layouts, but then in the constructor you define local variables with same names:

                        QHBoxLayout *horizontalLayout = new QHBoxLayout();
                        

                        Are you aware that this horizontalLayout is not the same you declared in your class? If you later try to access it your app will crash. Just do it like this in your constructor:

                        horizontalLayout = new QHBoxLayout();
                        
                        O Offline
                        O Offline
                        o6a6r9v1p
                        wrote on last edited by
                        #18

                        @jsulm
                        Thank you very much. Now I corrected the program , it is running.
                        Thanks to all who have helped me.

                        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
                        • Unsolved