Unable to put info from 1st class and use it into the 2nd



  • hello guys i'm trying to do a small exercise as a practice , i'm new to qt to bare with me if you see some dump architecture and misuse of classes,i just wanna fix this error so i can late rearrange it all here's the thing, it's a "class generator"(screen will show this) info from the 1st window are to be rearranged to look like a class code ,so here's the problem it doesn't print anything into the 2nd window it stays blank, i'm sure i'm doing some silly error somewhere but why my modest knowledge i can't see it here's the code :
    "mainwindow.h"
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QLabel>
    #include <QWidget>
    #include <QCheckBox>
    #include <QVBoxLayout>
    #include <QLineEdit>
    #include <QGridLayout>
    #include <QGroupBox>
    #include <QLayout>
    #include <QSpinBox>
    #include <QTextEdit>
    #include <QPushButton>
    class mainwindow:public QWidget{
    public:
    mainwindow();
    public slots:
    QString getName();
    QString getClass();
    QString getAuthor();
    QString getDate();
    QString getRole();
    QString getInfo();
    QPushButton *b2;
    private:
    QVBoxLayout *lay1;
    QLabel *lab2,*lab3,*lab4,*lab5,*lab6;
    QLineEdit *line1,*line2,*line3,*txt;
    QGridLayout *glay,*glay1;
    QVBoxLayout *vlay1,*vlay2;
    QCheckBox *ch1,*ch2,*ch3,*ch4;
    QSpinBox *spin1;
    QHBoxLayout *hlay;
    QPushButton *b1;

    };

    #endif // MAINWINDOW_H
    @
    "seconde.h"
    @#ifndef SECOND_H
    #define SECOND_H
    #include <QWidget>
    #include <QLabel>
    #include <QPushButton>
    #include <QBoxLayout>
    #include <QDialog>
    #include <QApplication>
    class second:public QDialog{
    Q_OBJECT
    public:
    second(QString s);
    QLabel *lab;

    private:
    QPushButton *but;
    QVBoxLayout *lay;
    };

    #endif // SECOND_H
    @
    "mainwindow.cpp"
    @#include "second.h"
    #include "mainwindow.h"
    mainwindow::mainwindow():QWidget(){

    QGroupBox *box2= new QGroupBox(tr("Class definition"));
    
    lab2= new QLabel("mother class");
    lab3= new QLabel("name");
    line1= new QLineEdit;
    line2= new QLineEdit;
    glay= new QGridLayout;
    glay->addWidget(lab3,1,0);
    glay->addWidget(line1,1,1);
    glay->addWidget(lab2,2,0);
    glay->addWidget(line2,2,1);
    box2->setLayout(glay);
    
    //1st part ends here,error free
    ch1= new QCheckBox("protect header again multiple inclusions",this);
    ch2= new QCheckBox("generate a constructor",this);
    ch3= new QCheckBox("generator destructor",this);
    ch4= new QCheckBox("generate a commenary space",this);
    vlay1= new QVBoxLayout;
            vlay1->addWidget(ch1);
            vlay1->addWidget(ch2);
            vlay1->addWidget(ch3);
            vlay1->addWidget(ch4);
    

    QGroupBox *box1= new QGroupBox(tr("Options"));
    box1->setLayout(vlay1);

    //end of part 2,error free

    lab4 = new QLabel("Author : ");
    lab5= new QLabel("Creation date");
    lab6 = new QLabel("role of the class");
    line3= new QLineEdit;
    spin1= new QSpinBox;
    txt= new QLineEdit;
    glay1 = new QGridLayout;
    glay1->addWidget(lab4,0,0);
    glay1->addWidget(line3,0,1);
    glay1->addWidget(lab5,1,0);
    glay1->addWidget(spin1,1,1);
    glay1->addWidget(lab6,2,0);
    glay1->addWidget(txt,2,1);
    QGroupBox *box3= new QGroupBox;
    box3->setLayout(glay1);
    //end of part 3,error free
    hlay = new QHBoxLayout;
    b1= new QPushButton("quit");
    b2= new QPushButton("generate");
    hlay->addWidget(b2);
    hlay->addWidget(b1);
    QGroupBox *box4= new QGroupBox;
    box4->setLayout(hlay);
    vlay2= new QVBoxLayout;
    vlay2->addWidget(box2);
    vlay2->addWidget(box1);
    vlay2->addWidget(box3);
    vlay2->addWidget(box4);

    setLayout(vlay2);
    //error free so far
    QObject::connect(b1,SIGNAL(clicked()),this,SLOT(close()));

    second a(getInfo());
    QObject::connect(b2,SIGNAL(clicked()),&a,SLOT(exec()));
    //this section espacially the b2 event is doubfull the b2 event doesn't work

    }
    //slots so far are functionals
    QString mainwindow::getName(){
    QString name=line1->text();
    return name;
    }
    QString mainwindow::getClass(){
    QString clas= line2->text();
    return clas;
    }
    QString mainwindow::getDate(){
    QString date =spin1->text();
    return date;
    }
    QString mainwindow::getRole(){
    QString role = txt->text();
    return role;
    }
    QString mainwindow::getAuthor(){
    QString author = line3->text();
    return author;
    }

    QString mainwindow::getInfo(){
    QString data=getName()+"\n"+getClass()+"\n"+getAuthor()+"\n"+getRole();
    return data;
    }
    @
    "second.cpp"
    @#include "second.h"
    second::second(QString s):QDialog(){
    lab= new QLabel(s);
    but= new QPushButton("ok");
    lay= new QVBoxLayout;
    lay->addWidget(lab);
    lay->addWidget(but);
    setLayout(lay);
    QObject::connect(but,SIGNAL(clicked()),this,SLOT(close()));
    }

    @
    "main.cpp"
    @#include "mainwindow.h"
    #include <QApplication>
    int main(int argc,char *argv[]){
    QApplication app(argc,argv);
    mainwindow wind;

    wind.show();
    
        return app.exec();
    

    }
    @
    and "generator.pro"
    @SOURCES +=
    mainwindow.cpp
    main.cpp
    second.cpp
    QT+=widgets
    QT+=opengl

    HEADERS +=
    mainwindow.h
    second.h
    @
    the task is far from over i even intend to add a source.cpp generator since i took the approach of debug by step i'm kinda blocked in here
    !http://imageshack.com/a/img196/4334/109r.png(screen)!
    again thx for reading and good day


  • Lifetime Qt Champion

    Hi,

    Your variable "a" goes out of scope at the end of the constructor so it's destroyed thus the connection disappears with a's desctruction


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.