Problem in calling user defined class in dialog.
Hey! I am Burhan
I am working on a periodic table in Qt c++.
The theme is when you click on the button of an element the properties of the respective element appears in the dialog.
Before working on the periodic table and design all buttons i want to test a one first.
While running the code simultator shows no error but when i click on the button it show me nothing and the error generates in the bottom window in pink color as " QWidget::setLayout: Attempting to set QLayout "" on class1 "", which already has a layout" here is the code.
Dialog::Dialog(QWidget *parent) :
ui->setupUi(this); class1 OB1; OB1.information();
Here is the user defined class code.
class1::class1(QWidget *parent) :
void class1 :: information (void)
QGridLayout *point = new QGridLayout;
QLabel *Calcium = new QLabel("Name");
QLabel *Helium = new QLabel("Symbol"); point->addWidget(Helium,1,0); QLabel *Hydrogen = new QLabel("Atomic mass"); point->addWidget(Hydrogen,2,0); QLabel *Nitrogen = new QLabel("Atomic Number"); point->addWidget(Nitrogen,3,0);
"this is the screen shot of the screen.. see the screen of mobile is blank after clicking on the pushbutton and as i clicked on the button it shows some error in the pink color on the status window.. ":http://www.facebook.com/photo.php?fbid=2545210849127&set=a.1095547328445.13509.1819453519&type=3&theater
Any help will highly be appriciated.
Your class1 constructor is calling class1::information() which sets the layout. Then in Dialog::Dialog() you're explicitly calling class1::information() again which tries to re-install a new layout.
then how can i resolve this problem ? sorry am not that much good at programming :(
Either remove line 15 from your first code snippet or line 9 from the second. OB1.information() is being called twice and, as such, class1::setLayout(point) is being called twice, which is what the error is referring to.
This is pretty basic C++ stuff. It would be beneficial to make sure you've got the very basics down before embarking on a large project.