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. Problem in calling user defined class in dialog.
Qt 6.11 is out! See what's new in the release blog

Problem in calling user defined class in dialog.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.2k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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 code.
    @#include "dialog.h"
    #include "ui_dialog.h"
    #include<QLabel>
    #include <QtGui>
    #include <QtCore>
    #include <class1.h>

    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {

    ui->setupUi(this);
    class1 OB1;
    OB1.information();
    

    }
    Dialog::~Dialog()
    {
    delete ui;
    }
    @

    Here is the user defined class code.
    @#include "class1.h"
    #include<QLabel>
    #include<QtGui>
    #include <QtCore>

    class1::class1(QWidget *parent) :
    QWidget(parent)
    {
    class1::information();
    }
    void class1 :: information (void)
    {
    QGridLayout *point = new QGridLayout;
    QLabel *Calcium = new QLabel("Name");
    point->addWidget(Calcium,0,0);

    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);
    

    class1::setLayout(point);
    class1::show();

    }
    @

    "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.
    Thanks.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      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.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        then how can i resolve this problem ? sorry am not that much good at programming :(

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          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.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          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