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. Using a secondary class to display things on my main screen.
Forum Updated to NodeBB v4.3 + New Features

Using a secondary class to display things on my main screen.

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 877 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.
  • C Offline
    C Offline
    callum.chalmers
    wrote on last edited by
    #1

    Hello,

    I currently have an application that displays different information on a front screen eg. speed + area. I'd like to basically create a menu overlay(on the same form) that I can control through a separate class. When I have tried implementing it, if I use .show() in the constructor for my menu overlay objects they all appear on the 'front screen' form. However if I try to attach .show() or .hide() to a button on the 'front screen', the application crashes. I have a feeling its because of the parents / inheritance but I'm not sure what part. Any help would be appreciated.

    Menu managing class - menumanager.c
    @
    #include "menumanager.h"

    #include <QtGui>

    MenuManager::MenuManager(QWidget *parent)
    : QWidget(parent)
    {
    Trips = new QWidget(parent);
    createSetupTrips();
    }

    void MenuManager::createSetupTrips()
    {
    QPushButton *Inputs = new QPushButton("Inputs");
    QPushButton *Channels = new QPushButton("Channels");
    QPushButton *System = new QPushButton("System");
    QPushButton *Machine = new QPushButton("Machine");
    QHBoxLayout *box = new QHBoxLayout();

    box->addWidget(Inputs);
    box->addWidget(Channels);
    box->addWidget(System);
    box->addWidget(Machine);
    
    Trips->setLayout(box);
    Trips->setGeometry(100,0,380,50);
    Trips->hide();
    

    }

    void MenuManager::showSetupTrips()
    {
    Trips->show();
    }
    @

    menumanager.h
    @
    #ifndef MENUMANAGER_H
    #define MENUMANAGER_H

    #include <QtGui>

    namespace Ui {
    class MenuManager;
    }

    class MenuManager : QWidget
    {
    Q_OBJECT

    public:
    MenuManager(QWidget *parent);
    void showSetupTrips();

    private:
    QWidget *Trips;
    void createSetupTrips();

    };
    #endif // MENUMANAGER_H
    @

    The constructor of mainwindow.c

    @
    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
    menus = new MenuManager(this);
    }
    @

    Then my main window had a button that would run this when clicked
    @
    void MainWindow::displayTrips(){

    menus->showSetupTrips();
    }
    @

    My definition in mainwindow.h
    @
    MenuManager *menus;
    @

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fahmy
      wrote on last edited by
      #2

      How do you attach the button with show and hide exactly? Did you use connect or what?

      Stay hungry, stay foolish.

      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