Creating a q widget
-
Hey guys , why every time I try to create a mainwindow in q widget I get a class with these stuff:
ui->setupUi(this);
namespace Ui {
class MainWindow;
}also why inherit from qmainwindow instead of qwidget ? in here
class MainWindow : public QMainWindow
,
what's the difference between doing this and creating a class that inherit from qwidget ?
for example this class that I used to create a calculator:
@
#ifndef CHECKCLASS_H
#define CHECKCLASS_H
#include<QLabel>
#include<QHBoxLayout>
#include<QLineEdit>
#include<QIntValidator>
#include<QWidget>
#include<QPushButton>
#include<QVBoxLayout>
#include<Qvector>
#include<QMessageBox>
#include<QMenu>
class checkclass : public QWidget
{
Q_OBJECT
public:
checkclass(QWidget *parent=0);private slots:
void convert(); void convert1(); void get_sum(); void get_mult(); void convertM(); void convertM1(); void get_div(); void convertD(); void convertD1(); void convertS(); void convertS1(); void get_sub(); private: QLabel *Sum_1; QLabel *Mult_1; QLabel *Div_1; QLabel *Sub_1; QMessageBox *Error; QVector<double>Cal; QPushButton *ReturnV; QPushButton *ReturnD; QPushButton *ReturnS; QLineEdit *Sub; QLineEdit *Sub1; QLineEdit *SubE; QLineEdit *edit; QLineEdit *edit1; QLineEdit *mult; QLineEdit *mult1; QLineEdit *multE; QLineEdit *Div; QLineEdit *Div1; QLineEdit *DivE; QLineEdit *E; QIntValidator *Valid; QHBoxLayout *left; QHBoxLayout *second; QHBoxLayout *third; QHBoxLayout *four; QVBoxLayout *LAY; QPushButton *ReturnV1; QHBoxLayout *Main; double z;
};
#endif // CHECKCLASS_H
@ -
Hi Project try ,
I'm not sure if I understand you well.
As you can see in the docs QMainWindow inherits from QWidget. So it is a QWidget. A lot of things have been implemented in there to help develop desktop applications with menubars, statusbars ...
It is possible to use QWidget or Qdialog as a base class
In step 3 of the wizard you can choose for a QWidget / QDialog / QMainWindow.
Did you use the wizard? -
Sorry man I'm new to i'm not sure what is wizard , I searched and found that it's a class so no I didn't use it , I just finished my first project and wanted to start on another but I was just wondering what is the difference between the two.
-
bq. I was just wondering what is the difference between the two.
As I said QMainWindow is a QWindow and has extra members compared to QWidget.
For your use case : a calculator QWidget will do.
Have a look at this "Getting started Guide":http://qt-project.org/doc/qt-5/gettingstartedqt.html
This explains the wizard and is a very usefull tool to start with.Happy coding
-
Thanks buddy.
-
My pleasure.
If you consider your question answered, could you please edit your first post's title and add [Solved]
thanks