Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

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



  • 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;
    @



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


Log in to reply