Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. create QT project without using form or qml
Forum Update on Monday, May 27th 2025

create QT project without using form or qml

Scheduled Pinned Locked Moved Solved Mobile and Embedded
3 Posts 2 Posters 712 Views
  • 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.
  • PopQtP Offline
    PopQtP Offline
    PopQt
    wrote on last edited by
    #1

    I have some experience in creating x11 applications using xlib. I am new to QT and I don't want to use any of the xlib calls.
    I used an empty qt project and added necessary class files in it. I used separate main.cpp and class for mainwindow. Now i would like to create only Qlabel in a separate class and assign mainwindow as it's parent.
    Here is my code:
    /main.cpp/

    #include <QtGui/QApplication>
    #include <mainwindow.h>
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        mainWindow mainWin;
        mainWin.showFullScreen();
        a.applicationName();
    
        return a.exec();
    }
    

    /mainwindow.h/

    #include <QMainWindow>
    
    class mainWindow : public QMainWindow
    {
        Q_OBJECT
    public:
        explicit mainWindow(QWidget *parent = 0);
        
    signals:
        
    public slots:
        
    };
    

    /mainwindow.cpp/

    #include "mainwindow.h"
    
    mainWindow::mainWindow(QWidget *parent) :
        QMainWindow(parent)
    {
    }
    

    /baseTextWin.h/

    #include <QLabel>
    #include <QString>
    class baseTextWin
    {
    public:
        QLabel* textWin;
    
        baseTextWin(,int x, int y, int width, int height); //would like to set mainwindow as parent
        void showTextWin();
        void hideTextWin();
    };
    

    /baseTextWin.cpp/

    #include "basetextwin.h"
    
    baseTextWin::baseTextWin(int x, int y, int width, int height)
    {
        textWin = new QLabel;
        textWin->setGeometry(x, y, width, height);
    
        hideTextWin();
    }
    void baseTextWin::showTextWin() {
        textWin->show();
    }
    
    void baseTextWin::hideTextWin() {
        textWin->hide();
    }
    

    now when I execute this, I get as separate windows. I want everything in one main window.

    JKSHJ 1 Reply Last reply
    0
    • PopQtP PopQt

      I have some experience in creating x11 applications using xlib. I am new to QT and I don't want to use any of the xlib calls.
      I used an empty qt project and added necessary class files in it. I used separate main.cpp and class for mainwindow. Now i would like to create only Qlabel in a separate class and assign mainwindow as it's parent.
      Here is my code:
      /main.cpp/

      #include <QtGui/QApplication>
      #include <mainwindow.h>
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          mainWindow mainWin;
          mainWin.showFullScreen();
          a.applicationName();
      
          return a.exec();
      }
      

      /mainwindow.h/

      #include <QMainWindow>
      
      class mainWindow : public QMainWindow
      {
          Q_OBJECT
      public:
          explicit mainWindow(QWidget *parent = 0);
          
      signals:
          
      public slots:
          
      };
      

      /mainwindow.cpp/

      #include "mainwindow.h"
      
      mainWindow::mainWindow(QWidget *parent) :
          QMainWindow(parent)
      {
      }
      

      /baseTextWin.h/

      #include <QLabel>
      #include <QString>
      class baseTextWin
      {
      public:
          QLabel* textWin;
      
          baseTextWin(,int x, int y, int width, int height); //would like to set mainwindow as parent
          void showTextWin();
          void hideTextWin();
      };
      

      /baseTextWin.cpp/

      #include "basetextwin.h"
      
      baseTextWin::baseTextWin(int x, int y, int width, int height)
      {
          textWin = new QLabel;
          textWin->setGeometry(x, y, width, height);
      
          hideTextWin();
      }
      void baseTextWin::showTextWin() {
          textWin->show();
      }
      
      void baseTextWin::hideTextWin() {
          textWin->hide();
      }
      

      now when I execute this, I get as separate windows. I want everything in one main window.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi @PopQt, you said you "would like to set mainwindow as parent". To do that, pass the parent widget's pointer into the child widget's constructor.

      Example:

      mainWindow::mainWindow(QWidget *parent) :
          QMainWindow(parent)
      {
          // Create a QLabel which shows the word "Hello",
          // and is nested inside this main window
          auto label = new QLabel("Hello", this);
          // ...
      }
      

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      PopQtP 1 Reply Last reply
      1
      • JKSHJ JKSH

        Hi @PopQt, you said you "would like to set mainwindow as parent". To do that, pass the parent widget's pointer into the child widget's constructor.

        Example:

        mainWindow::mainWindow(QWidget *parent) :
            QMainWindow(parent)
        {
            // Create a QLabel which shows the word "Hello",
            // and is nested inside this main window
            auto label = new QLabel("Hello", this);
            // ...
        }
        
        PopQtP Offline
        PopQtP Offline
        PopQt
        wrote on last edited by
        #3

        Thank you very much @JKSH . It worked.

        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