This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Problem with QLayout

Tags: None
(comma "," separated)
Anonymous Zebra
Karma
0

Problem with QLayout

Sat Feb 18, 2012 3:35 pm
I am currently trying to build a UI for a KDE app with two layouts, one nested within the other. Here's the code for mainwindow.cpp:

Code: Select all
#include "mainwindow.h"
 
MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent)
{
  KComboBox *driveCombo = new KComboBox;
  KComboBox *fsCombo = new KComboBox;
  QLabel *driveLabel = new QLabel;
  driveLabel->setText(i18n("Select drive to format:"));
  QLabel *fsLabel = new QLabel;
  fsLabel->setText(i18n("Select filesystem to format drive with:"));
 
  QHBoxLayout *buttonLayout = new QHBoxLayout;
  KPushButton *formatButton = new KPushButton;
  KPushButton *cancelButton = new KPushButton;
  buttonLayout->addWidget(formatButton);
  buttonLayout->addWidget(cancelButton);
 
  QVBoxLayout *guiLayout = new QVBoxLayout;
  guiLayout->addWidget(driveLabel);
  guiLayout->addWidget(driveCombo);
  guiLayout->addWidget(fsLabel);
  guiLayout->addWidget(fsCombo);
  guiLayout->addLayout(buttonLayout);

  QWidget *centralWidget = new QWidget;
  centralWidget->setLayout(layout);
 
  setCentralWidget(centralWidget);
 
  setupGUI();
}


When I try to compile I get this error:

Code: Select all
/home/kemra102/projects/KDE/kquickformat/src/mainwindow.cpp: In constructor ‘MainWindow::MainWindow(QWidget*)’:
/home/kemra102/projects/KDE/kquickformat/src/mainwindow.cpp:26:34: error: no matching function for call to ‘QWidget::setLayout(<unresolved overloaded function type>)’
/home/kemra102/projects/KDE/kquickformat/src/mainwindow.cpp:26:34: note: candidate is:
/usr/include/QtGui/qwidget.h:546:10: note: void QWidget::setLayout(QLayout*)
/usr/include/QtGui/qwidget.h:546:10: note:   no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘QLayout*’
make[2]: *** [src/CMakeFiles/kquickformat.dir/mainwindow.o] Error 1
make[1]: *** [src/CMakeFiles/kquickformat.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***


I have reviewed the Qt documentation and referred to a textbook I have and as far as I can tell I've done the layout's correctly, any ideas?
dikilroy
Registered Member
Posts
3
Karma
0
OS

Re: Problem with QLayout  Topic is solved

Sat Feb 18, 2012 4:16 pm
Hi,

I don't see where layout is defined.
The error message says that layout is a wrong type.
Is it a member of mainWindow?

cu
André
Anonymous Zebra
Karma
0

Re: Problem with QLayout

Sat Feb 18, 2012 4:50 pm
dikilroy wrote:Hi,

I don't see where layout is defined.
The error message says that layout is a wrong type.
Is it a member of mainWindow?

cu
André


Hi André, pointing out it was the wrong layout type made me think and I have spotted my error now. It was something I should have seen before but didn't. Line 26 was trying to set a layout that didn't exist (renamed from a previous version of my code!). Thanks for the kick I needed.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft