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. Getting variable from QDialog class in main window.

Getting variable from QDialog class in main window.

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 539 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.
  • M Offline
    M Offline
    madsm
    wrote on last edited by
    #1

    Hi, I have made a QDialong class import importdata, and when the user accepts the the results I would like to pass them variables to the mainwindow class with a QObject conenction with the following code:

    std::vector<std::string> names;
        std::vector<Vector3> start_pos;
        std::vector<double> radii;
    
        auto *importDataDialog = new importdata(this);
    
        QObject::connect(this->ui->importDataButton, &QPushButton::clicked,
                         importDataDialog, &QDialog::open);
    
        QObject::connect(importDataDialog, &QDialog::accepted,
                        [=](){
                            start_pos = importDataDialog->get_pos();
                            radii = importDataDialog->get_radii();
                            names = importDataDialog->get_names();
                            this->populateCombos(names);
                            this->ui->comboBoxCamPos->setEnabled(true);
                            this->ui->comboBoxCamCenter->setEnabled(true);
                        });
    
    

    However when I try to compile I get this error

    In lambda function:
    /xxx/mainwindow.cpp:45:63: error: passing ‘const std::vector<Vector3>’ as ‘this’ argument discards qualifiers [-fpermissive]
                             start_pos = importDataDialog->get_pos();
    

    The get_pos() and other functions are defined as:

    namespace Ui {
    class importdata;
    }
    
    class importdata : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit importdata(QWidget *parent = 0);
        ~importdata();
    
        std::vector<Vector3> get_pos() const { return  body_positions;};
        std::vector<double> get_radii() const { return body_radii;};
        std::vector<std::string> get_names() const { return body_names;};
    
    private:
        Ui::importdata *ui;
    
        std::vector<Vector3> body_positions;
        std::vector<double > body_radii;
        std::vector<std::string> body_names;
    };
    
    

    I am using Qt5.9.1 and C++11
    Thnaks in advance!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      madsm
      wrote on last edited by
      #2

      This seems to work:

      QObject::connect(importDataDialog, &QDialog::accepted,
          [=]() {
              this->populateCombos(importDataDialog->get_names());
              this->ui->comboBoxCamPos->setEnabled(true);
              this->ui->comboBoxCamCenter->setEnabled(true); }
          );
      
      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved