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. QBoxLayout is not shown properly
Qt 6.11 is out! See what's new in the release blog

QBoxLayout is not shown properly

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 254 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.
  • sankarapandiyanS Offline
    sankarapandiyanS Offline
    sankarapandiyan
    wrote on last edited by sankarapandiyan
    #1

    I tried to create a some textedit and pushbutton in layout without using UI . But i have received the plain latout at the End and i have these type of Error .

    QWidget::setLayout: Attempting to set QLayout "" on MainWindow "MainWindow", which already has a layout
    QObject::connect: Parentheses expected, slot MainWindow::writetoFile in ../serial_mannualselct/mainwindow.cpp:34
    QObject::connect: (receiver name: 'MainWindow')

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        setWindowTitle("TITLE");
        cBox  = new QComboBox;
        Save   = new QPushButton;
        SBox   = new QSpinBox;
        tEdit = new QTextEdit;
        Hlay  = new QHBoxLayout;
    
        cBox->addItem("First");
        cBox->addItem("Second");
        cBox->addItem("third");
        Save->setText("save");
    
        Hlay->addWidget(SBox);
        Hlay->addWidget(tEdit);
        Hlay->addWidget(cBox);
        Hlay->addWidget(Save);
        setLayout(Hlay);
    
        MainWindow::connect(Save, SIGNAL(clicked()), this, SLOT (writetoFile));// I think here there is a problem 
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::writetoFile(){
        QString fname = "/home/adx-soft1/Shankar/serial_mannualselct/file.txt";
        QFile file(fname);
        if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            QTextStream stream(&file);
            QString textFromSpin = QString::number(SBox->value());
            QString textFromBox  = tEdit->toPlainText();
            QString textFromCombo= cBox->currentText();
           stream << "Spinner value"    << endl ;
           stream << "TEXT FROM BOX"    << endl ;
           stream << "TEXT FROM COMBO"  << endl 
    
    
        file.close();
        }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      QMainWindow already has a layout, the one that manages the docked widgets, tool bars, etc.

      Put your stuff inside a plain QWidget and use it as central widget.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4

      • Login

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