Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Nested Map QDialog sharing



  • I have this class:

    namespace Ui {
    class Components;
    }
    
    class Components : public QDialog
    {
        Q_OBJECT
        void AddRoot(QString name, QString codigo, int quantidade);
    public:
        explicit Components(QWidget *parent = nullptr);
        ~Components();    
    private slots:    
        void on_pbAdd_clicked();
        void on_pbSearch_clicked();
        void on_pbDelete_clicked();
    protected:     
         QMap<QString, QMap<QString, int>>  CompMap; 
    private:
        Ui::Components *ui;
    

    and this class:

    namespace Ui {
    class Calendario;
    }
    
    class Calendario : public QDialog
    {
       
    public:
        explicit Calendario(QWidget *parent = nullptr);
        ~Calendario();
        
        Q_OBJECT
    
    public slots:   
        void setValuesCal(QMap<QString, QMap<QString, int>>);
    signals:  
        void valueChengedCal(QMap<QString, QMap<QString, int>>);    
    private slots:
       
        void setReservation(QDate &date);
        void getReservation(QDate &date);
        void delReservation(QDate &date);
        QDate on_calendarWidget_clicked(const QDate &date);
        void on_lineEdit_textChanged(const QString &nome);
        void on_lineEdit_2_textChanged(const QString &codigo);
    
    private:
        void setFontSize(int size);
    
        Ui::Calendario *ui;
        QDate * selecteddate;
        
    
    

    I add,remove and edit all values of the QMap in the Components and I want to be able to edit only int value of said QMap on my class Calendario.
    Fist question is: is this a good approach to the subject.
    Second question: how would I go about sharing the data in one Dialog and the other since, as I understand it it, I can't pass it as a signal.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    If you only want to change the int values contained in CompMap then give Components a proper API that allows to give the parameters need to make that happen.

    As for the design question, based on the code, it's likely not going to be clean. Can you explain exactly what you want to implement ?

    The naming itself is so generic that it does not allow to really give an answer.



  • i'm implementing and item electronic component management system system.
    I have those two classes. and a main window.

    In main window I just have 2 functions which are used to open the dialogs:

    void MainWindow::on_actionComp_Manager_triggered()
    {
        Component = new Components;
        Component->show();
    }
    
    void MainWindow::on_actionReservas_triggered()
    {
        Calendar = new Calendario;
        Calendar ->show();
    }
    

    The components class is where I add items to map which have:
    name = fist map key (QString)
    code = nested map key (QString)
    number_of_items = nested map value(int)

    The map is up and running and I can manage them.

    The Calendario class is a calendar where I need to:

    pick a code and pick a number_of_items from said Map and select a date from calendar;
    I used this to get the date:

    QDate Calendario::on_calendarWidget_clicked(const QDate &date)
    {
        *selecteddate = date;
        qDebug() << *selecteddate;
        return *selecteddate;
    }
    

    and remove said item quantity from that map for as long as the day picked isn't over.

    And I will eventually need to get that info on file.

    I was going to create map in the Calendario class to store the codes and quantities extracted from the other map and save them individually.

    I would really appreciate the help. I went through the Documentation but I don't seem to find a way.
    Thanks in advance


  • Lifetime Qt Champion

    @ASCsk said in Nested Map QDialog sharing:

    QDate Calendario::on_calendarWidget_clicked(const QDate &date)
    {
    *selecteddate = date;
    qDebug() << *selecteddate;
    return *selecteddate;
    }

    This screams for cleanup. There's no need to allocate a QDate on the heap.

    In any case, from your description, you should really consider using a database. Please take the time to go through the corresponding chapter in Qt's documentation as well as read the examples.


Log in to reply