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. Creating a q widget
Forum Updated to NodeBB v4.3 + New Features

Creating a q widget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.6k 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.
  • P Offline
    P Offline
    Project try
    wrote on last edited by
    #1

    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
    @

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      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?

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Project try
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          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

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Project try
            wrote on last edited by
            #5

            Thanks buddy.

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              My pleasure.

              If you consider your question answered, could you please edit your first post's title and add [Solved]
              thanks

              Qt Certified Specialist
              www.edalsolutions.be

              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