Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Passing QRadioButton value from one window to another window in Qt (no matching function for call to)

    General and Desktop
    2
    11
    4126
    Loading More Posts
    • 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.
    • S
      srivatsa last edited by

      I want to pass selected QRadioButton's value from one Window to another. I am confused with the function declaration to accept the text value in Second Window, here is my code.

      Window1.cpp

      @void SelectOS :: processNextButton(){
      if(ui->win32->isChecked()){
      QString loc = "WIN/32Bit";
      SelectSoftware *ss = new SelectSoftware (loc);
      this->hide();
      ss->show();
      }
      else
      {
      //QMessageBox:warning();
      }
      }@

      Window2.h

      @public:
      SelectSoftware(const QString &text, QWidget *parent=0);@

      Window2.cpp

      @SelectSoftware::SelectSoftware(const QString &text, QWidget *parent):QMainWindow(parent),ui(new ui::SelectSoftware)
      {
      QString softpath = text;
      qDebug << softpath;
      }@

      But when I call

      @ss = new SelectSoftware();@

      OR

      @ss= new SelectSoftware(const QString &text, QWidget *parent);@

      in Window2.cpp, I get the error : no matching function for call to SelectSoftware::SelectSoftware()

      Where am I wrong?

      1 Reply Last reply Reply Quote 0
      • S
        Sam last edited by

        For you second window do you have a default constructor SelectSoftware() declared in your header file ? Or else specify a default text value for your QString.

        @class SelectSoftware : public QWidget
        {
        Q_OBJECT
        public:
        explicit SelectSoftware(QWidget *parent = 0);
        };@

        1 Reply Last reply Reply Quote 0
        • S
          srivatsa last edited by

          Thanks sam, I need this loc variable to be available in each every function definition in Window2.cpp, how can I do this??

          1 Reply Last reply Reply Quote 0
          • S
            Sam last edited by

            For your constructor you can set the default values as

            @SelectSoftware(const QString &text = "", QWidget *parent=0);@

            which will set the default value of text to empty string, if you pass the string values while creating an instance of SelectorSodtware then it will take that value.

            1 Reply Last reply Reply Quote 0
            • S
              srivatsa last edited by

              Well, now I'll tell my problem: in Window2.cpp, there is one SLOT called
              test(),
              in that test, its being defined as
              ss = new SelectSoftware ,
              as we've provided arguments
              QString &text,
              I've modified to
              ss = new SelectSoftware(text).
              But this is creating the problem, again its executing
              SelectSoftware(text)
              function, where the value of text has become empty and the application is crashing!!!

              1 Reply Last reply Reply Quote 0
              • S
                Sam last edited by

                Can you post a test code that relects the same behaviour. It will be helpful for us to understand your requirements.

                1 Reply Last reply Reply Quote 0
                • S
                  srivatsa last edited by

                  Window2.cpp

                  @void SelectSoftware::showMainPage()
                  {
                  ss = new SelectSoftware(softpath); // here its creating problem, not going forward and app is crashing!!!

                  for(int j = 0; j < softwareList.size(); j++){
                      if(checkBox[j]->isChecked()){
                          if(!comboBox[j]->currentIndex()){
                              QMessageBox::warning(this, "Select version !", "Select version number for all selected software");
                              return;
                          }
                      }
                  }
                  
                  for(int i = 0; i < softwareList.size(); i++){
                      if(checkBox[i]->isChecked()){
                          ss->selectedSoftList.push_back(checkBox[i]->text());
                          ss->selectedVerList.push_back(comboBox[i]->currentText());
                      }
                  }
                  
                  if(!ss->selectedSoftList.size()){
                      QMessageBox::warning(this, "No product Selected !", "Select one");
                      return;
                  }
                  

                  else{
                  SelectionPage* sp = new SelectionPage;
                  this->hide();
                  sp->show();
                  }
                  }

                  void SelectSoftware::test(const int id)
                  {
                  if(checkBox[id]->isChecked()){
                  comboBox[id]->setEnabled(true);
                  comboBox[id]->addItem(" Select anyone ");
                  QString path = qApp->applicationDirPath() + "/products/" + checkBox[id]->text();

                      QDir dir;
                      dir.cd(path);
                      dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
                  
                      QFileInfoList list = dir.entryInfoList();
                      for (int i = 0; i < list.size(); ++i) {
                          QFileInfo fileInfo = list.at(i);
                          comboBox[id]->addItem(fileInfo.fileName());
                      }
                  
                  }else{
                      comboBox[id]->clear();
                      comboBox[id]->setDisabled(true);
                  }
                  

                  }

                  void SelectSoftware::getSoftwareDetails()
                  {
                  QString fileName = qApp->applicationDirPath() + "/abc/" + SOFTWARELIST;
                  QFile file(fileName);
                  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
                  QString msg = "Could not find the file " + fileName;
                  errorExit(msg);
                  }

                  QTextStream in(&file);
                  while (!in.atEnd()) {
                      QString line = in.readLine();
                      processLine(line.toLower());
                  }
                  

                  }

                  void SelectSoftware::processLine(QString str)
                  {
                  QStringList list = str.split(",");
                  QDir path = qApp->applicationDirPath() + "/products/" + list[0];
                  if(path.exists() && (list.size() == 2)){
                  QString tmp = list[0];
                  tmp = tmp.toLower();
                  softwareList.push_back(tmp);
                  }
                  }

                  void SelectOption::initializeUi()
                  {
                  this->setWindowTitle("Window2");

                  QGridLayout *gridLayout1 = new QGridLayout();
                  gridLayout1->setMargin(5);
                  gridLayout1->setSpacing(5);
                  
                  QSignalMapper* signalMapper = new QSignalMapper();
                  
                  for(int i = 0; i < list.size(); i++){
                      radioButton[i] = new QRadioButton();
                      radioButton[i]->setText(softwareList[i]);
                      signalMapper->setMapping(radioButton[i], i);
                      gridLayout1->addWidget(radioButton[i], i/1, i%1);
                      connect(radioButton[i], SIGNAL(clicked()),signalMapper, SLOT(map()));
                  }
                  

                  connect(signalMapper, SIGNAL(mapped(const int &)),this, SIGNAL(radioChecked(const int &)));
                  connect(this, SIGNAL(radioChecked(const int &)),this, SLOT(test(const int)));

                  QGridLayout *gridLayout2 = new QGridLayout();
                  gridLayout2->setMargin(5);
                  gridLayout2->setSpacing(5);
                  
                  for(int j = 0; j < list.size(); j++){
                      comboBox[j] = new QComboBox();
                      comboBox[j]->setDisabled(true);
                      gridLayout2->addWidget(comboBox[j], j/1, j%1);
                  }
                  
                  QPushButton *nextButton = new QPushButton("Next >");
                  nextButton->setDefault(true);
                  connect(nextButton, SIGNAL(clicked()), this, SLOT(showMainPage()));
                  
                  QPushButton *backButton = new QPushButton("< Back");
                  backButton->setDefault(true);
                  connect(backButton, SIGNAL(clicked()), this,     SLOT(showSelectOS()));
                  
                  QPushButton *cancelButton = new QPushButton("Cancel");
                  cancelButton->setDefault(true);
                  connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
                  
                  QHBoxLayout *hboxlayout;
                  hboxlayout = new QHBoxLayout();
                  hboxlayout->addLayout(gridLayout1);
                  hboxlayout->addLayout(gridLayout2);
                  
                  QHBoxLayout *layout;
                  layout = new QHBoxLayout();
                  layout->addStretch(10);
                  layout->addWidget(nextButton);
                  layout->addWidget(backButton);
                  layout->addWidget(cancelButton);
                  layout->addStretch(10);
                  
                  QVBoxLayout *mainLayout;
                  mainLayout = new QVBoxLayout();
                  mainLayout->addLayout(hboxlayout);
                  mainLayout->addLayout(layout);
                  ui->centralwidget->setLayout(mainLayout);
                  

                  }

                  QVector<QString> SelectSoftware::getSelectedSoftware()
                  {
                  return ss->selectedSoftList;
                  }

                  QVector<QString> SelectSoftware::getSelectedVersion()
                  {
                  return ss->selectedVerList;
                  }

                  QStringList SelectSoftware::getSelectedModules()
                  {
                  return selectedModuleList;
                  }
                  @

                  1 Reply Last reply Reply Quote 0
                  • S
                    Sam last edited by

                    What happens inside the constructor of SelectSoftware class ? where is initializeUi called ?

                    1 Reply Last reply Reply Quote 0
                    • S
                      srivatsa last edited by

                      Here is the code of SelectSoftware Constructor...

                      @#include "selectsoftware.h"
                      #include "ui_selectsoftware.h"

                      SelectSoftware *ss;
                      QStringList selectedModuleList;

                      SelectSoftware::SelectSoftware(const QString &text, QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::SelectSoftware)
                      {
                      ui->setupUi(this);
                      softpath = text;
                      setWindowPosition();
                      getSoftwareDetails();
                      initializeUi();
                      }

                      SelectSoftware::~SelectSoftware()
                      {
                      delete ui;
                      }

                      void SelectSoftware::setWindowPosition()
                      {
                      QDesktopWidget *desktop = QApplication::desktop();
                      int x = (desktop->width() - size().width())/2;
                      int y = (desktop->height() - size().height())/2;
                      move(x, y-50);
                      setFixedSize(size().width(), size().height());
                      }

                      void SelectSoftware::cancel()
                      {
                      qApp->exit(0);
                      }@

                      1 Reply Last reply Reply Quote 0
                      • S
                        srivatsa last edited by

                        Can we pass multiple text parameter values to @SelectSoftware::SelectSoftware(const QString &text, QWidget *parent)@
                        or we need to do like @SelectSoftware::SelectSoftware(const QString &text,const QString &path, QWidget *parent)@ to pass another variable ??

                        1 Reply Last reply Reply Quote 0
                        • S
                          Sam last edited by

                          Yes you need to provide the argument type / number of arguments in the function declaration.

                          I still have doubts with your implemetation, a new instance of the same class is created each time showMainPage() is called, why is it required shouldnt it be handled from outside.

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post