Calling Classes with signal slots like a function
Unsolved
General and Desktop
-
Hello I am new to Qt creator and also to C++
i have two classes. first is main class in which i have a ui with only a push buttons. second i have another class which add a label and and qlineedit. Now to to call the second class when the puchbutton is clicked. please find below the code
this is mainwindow
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QLayout> #include <QFormLayout> #include <QButtonGroup> #include <QLineEdit> #include <QRect> #include <QStyle> #include <QScrollArea> #include <QtSql> #include <QDebug> #include <QtGui> #include <QtCore> #include <QDialog> #include <QLabel> #include <QMessageBox> #include "new_class.h" namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_pushButton_clicked(); private: Ui::MainWindow *ui; QFormLayout* viewLayout; new_class* tab_1; }; #endif // MAINWINDOW_H
.cpp file
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { // dont know how to call ??????? }
second call start from here
#ifndef NEW_CLASS_H #define NEW_CLASS_H #include <QWidget> #include <QLineEdit> #include <QLayout> #include <QFormLayout> #include <QButtonGroup> #include <QRect> #include <QStyle> #include <QScrollArea> #include <QtSql> #include <QDebug> #include <QtGui> #include <QtCore> #include <QDialog> #include <QLabel> #include <QMessageBox> class new_class : public QWidget { Q_OBJECT public: explicit new_class(QWidget *parent = 0); signals: public slots: private: QLineEdit *new_line; QFormLayout* viewLayout; }; #endif // NEW_CLASS_H
second call .cpp file
#include "new_class.h" new_class::new_class(QWidget *parent) : QWidget(parent) { viewLayout = new QFormLayout(this); QWidget* scrollAreaContent = new QWidget(this); scrollAreaContent->setLayout( viewLayout ); QScrollArea* scrollArea = new QScrollArea(this); scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); scrollArea->setWidgetResizable( true ); scrollArea->setWidget( scrollAreaContent ); scrollArea->setGeometry(250,250,700,500); scrollArea->setEnabled(true); scrollArea->show(); QLabel *L = new QLabel("ANYTHING THAT PASS TO IT", this); QLineEdit *Q = new QLineEdit("Just to Check",this); L->setBuddy(Q); viewLayout->addWidget(L); viewLayout->addWidget(Q); L->show(); Q->show(); }
-
@sumit-yadav said in Calling Classes with signal slots like a function:
where
@VRonin said in Calling Classes with signal slots like a function:
in your designer
i mean Qt Desinger to be clear
@sumit-yadav said in Calling Classes with signal slots like a function:
how
@VRonin said in Calling Classes with signal slots like a function:
right click on it and promote it
-