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. SIGSEGV in fromStdString
Forum Updated to NodeBB v4.3 + New Features

SIGSEGV in fromStdString

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 7 Posters 3.7k Views 2 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.
  • R Robert M.

    @ChrisW67
    I don't know why Qt forum did not display asterisk before parameter parentWindow.

    OtherOptionsDialog::OtherOptionsDialog(QWidget *parent, MainWindow *parentWindow) :
        QDialog(parent),
        ui(new Ui::OtherOptionsDialog),
        mainWindow(parentWindow)
    {
    
    Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #13

    @Robert-M said in SIGSEGV in fromStdString:

    don't know why Qt forum did not display asterisk before parameter parentWindow.

    Because you don't format your code properly - use the format tags provided by the forum software!

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    1 Reply Last reply
    2
    • R Robert M.

      @ChrisW67
      I don't know why Qt forum did not display asterisk before parameter parentWindow.

      OtherOptionsDialog::OtherOptionsDialog(QWidget *parent, MainWindow *parentWindow) :
          QDialog(parent),
          ui(new Ui::OtherOptionsDialog),
          mainWindow(parentWindow)
      {
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #14

      @Robert-M
      As @Christian-Ehrlicher said, please use the forum's Code tags to enclose blocks of code you want others to look at.

      If you want an answer please reduce your code to some kind of minimal example. Literally the majority of the code you show cannot be relevant to your issue: message boxes, regular expressions, validators, spinboxes, line edits, etc. etc. How are these required or implicated? If you reduce your code to a minimum then maybe either you will spot the problem yourself or someone else will.

      1 Reply Last reply
      2
      • R Robert M.

        @ChrisW67
        I don't know why Qt forum did not display asterisk before parameter parentWindow.

        OtherOptionsDialog::OtherOptionsDialog(QWidget *parent, MainWindow *parentWindow) :
            QDialog(parent),
            ui(new Ui::OtherOptionsDialog),
            mainWindow(parentWindow)
        {
        
        R Offline
        R Offline
        Robert M.
        wrote on last edited by
        #15

        @Robert-M
        I tried to run the code in Linux.
        I see:
        terminate called after throwing an instance of 'std::bad_alloc'
        what(): std::bad_alloc
        Aborted (core dumped)

        JonBJ 1 Reply Last reply
        0
        • R Robert M.

          @Robert-M
          I tried to run the code in Linux.
          I see:
          terminate called after throwing an instance of 'std::bad_alloc'
          what(): std::bad_alloc
          Aborted (core dumped)

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #16

          @Robert-M
          Great. So what are you going to do to simplify to find out why? The code you have posted is on the one hand too large and on the other incomplete.

          Let's take a "random" example of what could be going on in your code, for all we know:

          char array1[4];
          std::string extensions;
          char array2[4];
          ...
          memcpy(array1, "12345678", 8);
          memcpy(array2, "12345678", 8);
          ...
          qDebug() << mainwindow->extensions;
          

          (I put in both above & below because not sure which direction stack/member layout grows.) It's an example. That's why you need to create and paste a minimal example of actual code going wrong....

          1 Reply Last reply
          1
          • R Robert M.

            @Christian-Ehrlicher

            void MainWindow::on_actionSet_other_options_triggered()
            {
                action_cancelled = false;
                if (mode == "B") {
                    if (QMessageBox::information(this, "Information", "You will be asked to set some additional options. Note that obfuscating properties/variables depend on framework code (for example CodeIgniter does not allow for obfuscating variables in views because such variables are passed as view parameters in controller).", QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) {
                        action_cancelled = true;
                        return;
                    }
                }
                OtherOptionsDialog *options = new OtherOptionsDialog(this, this); // !!! this IS NOT nullptr
                options->exec();
                set_dirtyphp_command("");
                set_menu_options();
            }
            
            OtherOptionsDialog::OtherOptionsDialog(QWidget *parent, MainWindow *parentWindow) :
                QDialog(parent),
                ui(new Ui::OtherOptionsDialog),
                mainWindow(parentWindow) // !!! HERE INITIALISATION
            {
                ui->setupUi(this);
                setFixedSize(size());
                ui->checkBox->setChecked(!mainWindow->no_check);
                ui->checkBox_5->setChecked(mainWindow->allow_reflection);
                ui->spinBox->setMinimum(::min_random_identifiers_length);
                ui->spinBox->setMaximum(::default_random_identifiers_length * 3);
                ui->spinBox->setValue(mainWindow->random_identifiers_length);
                ui->lineEdit->setValidator(new QIntValidator(ui->lineEdit));
                ui->lineEdit->setText(QString::fromStdString(std::to_string(mainWindow->max_line_len)));
                QRegularExpression rx1("([a-zA-Z0-9_\\-\\+]+,)*[a-zA-Z0-9_\\-\\+]+");
                QValidator *validator1 = new QRegularExpressionValidator(rx1, ui->lineEdit_2);
                ui->lineEdit_2->setValidator(validator1);
                Q_ASSERT(mainWindow != nullptr);
                Q_ASSERT(mainWindow->extensions != std::string(""));
                std::string e = mainWindow->extensions; //!!! SIGSEGV
                QString qs = QString::fromStdString(e);
                ui->lineEdit_2->setText(qs);
                ui->checkBox_2->setChecked(mainWindow->obfpctl);
                ui->checkBox_3->setChecked(mainWindow->obfpmdl);
                ui->checkBox_6->setChecked(mainWindow->obfpvw);
                ui->checkBox_4->setChecked(mainWindow->obfvvw);
                ui->lineEdit_3->setText(QString::fromStdString(mainWindow->reserved));
                QRegularExpression rx2(QString::fromStdString("(" + ::identifier + ",)*(" + ::identifier + ")?"));
                QValidator *validator2 = new QRegularExpressionValidator(rx2, ui->lineEdit_3);
                ui->lineEdit_3->setValidator(validator2);
            }
            
            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #17

            @Robert-M said in SIGSEGV in fromStdString:

            OtherOptionsDialog::OtherOptionsDialog(QWidget *parent, MainWindow parentWindow) :
            QDialog(parent),
            ui(new Ui::OtherOptionsDialog),
            mainWindow(parentWindow) // !!! HERE INITIALISATION
            {
            ui->setupUi(this);
            setFixedSize(size());
            ui->checkBox->setChecked(!mainWindow->no_check);
            ui->checkBox_5->setChecked(mainWindow->allow_reflection);
            ui->spinBox->setMinimum(::min_random_identifiers_length);
            ui->spinBox->setMaximum(::default_random_identifiers_length * 3);
            ui->spinBox->setValue(mainWindow->random_identifiers_length);
            ui->lineEdit->setValidator(new QIntValidator(ui->lineEdit));
            ui->lineEdit->setText(QString::fromStdString(std::to_string(mainWindow->max_line_len)));
            QRegularExpression rx1("([a-zA-Z0-9_\-\+]+,)
            [a-zA-Z0-9_\-\+]+");
            QValidator validator1 = new QRegularExpressionValidator(rx1, ui->lineEdit_2);
            ui->lineEdit_2->setValidator(validator1);
            Q_ASSERT(mainWindow != nullptr);
            Q_ASSERT(mainWindow->extensions != std::string(""));
            std::string e = mainWindow->extensions; //!!! SIGSEGV
            QString qs = QString::fromStdString(e);
            ui->lineEdit_2->setText(qs);
            ui->checkBox_2->setChecked(mainWindow->obfpctl);
            ui->checkBox_3->setChecked(mainWindow->obfpmdl);
            ui->checkBox_6->setChecked(mainWindow->obfpvw);
            ui->checkBox_4->setChecked(mainWindow->obfvvw);
            ui->lineEdit_3->setText(QString::fromStdString(mainWindow->reserved));
            QRegularExpression rx2(QString::fromStdString("(" + ::identifier + ",)
            (" + ::identifier + ")?"));
            QValidator *validator2 = new QRegularExpressionValidator(rx2, ui->lineEdit_3);
            ui->lineEdit_3->setValidator(validator2);
            }

            Instead of passing this twice to your OtherOptionsDialog as QWidget and QMainWindow to access some data, you should pass the data directly. You seem to read-only anyway.
            I assume, obfpctl, obfpmdl, obfpvw and obfvvw are boolean and extensions is a string.
            So change

            OtherOptionsDialog::OtherOptionsDialog(QWidget *parent, MainWindow *parentWindow) :
                QDialog(parent),
                ui(new Ui::OtherOptionsDialog),
                mainWindow(parentWindow) // !!! HERE INITIALISATION
            

            to something like

            OtherOptionsDialog::OtherOptionsDialog(QWidget *parent, QVector<QVariant> &data) :
                QDialog(parent),
                ui(new Ui::OtherOptionsDialog)
            

            and pass the data with c'tor

            
            QVector<QVariant> data;
            data.push_back(obfpctl);
            data.push_back(obfpmdl);
            data.push_back(obfpvw);
            data.push_back(obfvvw);
            data.push_back(QString::fromStdString(extensions);
            
            OtherOptionsDialog *options = new OtherOptionsDialog(this, data);
            

            Since it's a constant data structure, you know the order of your data and can access it with data.at(...) or data[...] in your dialog class.
            It's weird to pass the whole mainWindow to an options dialog just to read some variables.
            Maybe you want to re-think your whole design


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            R 1 Reply Last reply
            0
            • Pl45m4P Pl45m4

              @Robert-M said in SIGSEGV in fromStdString:

              OtherOptionsDialog::OtherOptionsDialog(QWidget *parent, MainWindow parentWindow) :
              QDialog(parent),
              ui(new Ui::OtherOptionsDialog),
              mainWindow(parentWindow) // !!! HERE INITIALISATION
              {
              ui->setupUi(this);
              setFixedSize(size());
              ui->checkBox->setChecked(!mainWindow->no_check);
              ui->checkBox_5->setChecked(mainWindow->allow_reflection);
              ui->spinBox->setMinimum(::min_random_identifiers_length);
              ui->spinBox->setMaximum(::default_random_identifiers_length * 3);
              ui->spinBox->setValue(mainWindow->random_identifiers_length);
              ui->lineEdit->setValidator(new QIntValidator(ui->lineEdit));
              ui->lineEdit->setText(QString::fromStdString(std::to_string(mainWindow->max_line_len)));
              QRegularExpression rx1("([a-zA-Z0-9_\-\+]+,)
              [a-zA-Z0-9_\-\+]+");
              QValidator validator1 = new QRegularExpressionValidator(rx1, ui->lineEdit_2);
              ui->lineEdit_2->setValidator(validator1);
              Q_ASSERT(mainWindow != nullptr);
              Q_ASSERT(mainWindow->extensions != std::string(""));
              std::string e = mainWindow->extensions; //!!! SIGSEGV
              QString qs = QString::fromStdString(e);
              ui->lineEdit_2->setText(qs);
              ui->checkBox_2->setChecked(mainWindow->obfpctl);
              ui->checkBox_3->setChecked(mainWindow->obfpmdl);
              ui->checkBox_6->setChecked(mainWindow->obfpvw);
              ui->checkBox_4->setChecked(mainWindow->obfvvw);
              ui->lineEdit_3->setText(QString::fromStdString(mainWindow->reserved));
              QRegularExpression rx2(QString::fromStdString("(" + ::identifier + ",)
              (" + ::identifier + ")?"));
              QValidator *validator2 = new QRegularExpressionValidator(rx2, ui->lineEdit_3);
              ui->lineEdit_3->setValidator(validator2);
              }

              Instead of passing this twice to your OtherOptionsDialog as QWidget and QMainWindow to access some data, you should pass the data directly. You seem to read-only anyway.
              I assume, obfpctl, obfpmdl, obfpvw and obfvvw are boolean and extensions is a string.
              So change

              OtherOptionsDialog::OtherOptionsDialog(QWidget *parent, MainWindow *parentWindow) :
                  QDialog(parent),
                  ui(new Ui::OtherOptionsDialog),
                  mainWindow(parentWindow) // !!! HERE INITIALISATION
              

              to something like

              OtherOptionsDialog::OtherOptionsDialog(QWidget *parent, QVector<QVariant> &data) :
                  QDialog(parent),
                  ui(new Ui::OtherOptionsDialog)
              

              and pass the data with c'tor

              
              QVector<QVariant> data;
              data.push_back(obfpctl);
              data.push_back(obfpmdl);
              data.push_back(obfpvw);
              data.push_back(obfvvw);
              data.push_back(QString::fromStdString(extensions);
              
              OtherOptionsDialog *options = new OtherOptionsDialog(this, data);
              

              Since it's a constant data structure, you know the order of your data and can access it with data.at(...) or data[...] in your dialog class.
              It's weird to pass the whole mainWindow to an options dialog just to read some variables.
              Maybe you want to re-think your whole design

              R Offline
              R Offline
              Robert M.
              wrote on last edited by
              #18

              @Pl45m4
              According to your advice I defined struct other_options.
              Program works fine, there's no SIGSEGV.
              Problem solved.
              Thanks.

              R 1 Reply Last reply
              0
              • R Robert M.

                @Pl45m4
                According to your advice I defined struct other_options.
                Program works fine, there's no SIGSEGV.
                Problem solved.
                Thanks.

                R Offline
                R Offline
                Robert M.
                wrote on last edited by
                #19

                @Robert-M
                Using struct instead of QVector<QVariant> produced simpler and smaller code.
                What is adventage of using QVector<QVariant> instead of struct?

                jsulmJ JonBJ 2 Replies Last reply
                0
                • R Robert M.

                  @Robert-M
                  Using struct instead of QVector<QVariant> produced simpler and smaller code.
                  What is adventage of using QVector<QVariant> instead of struct?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #20
                  This post is deleted!
                  R 1 Reply Last reply
                  0
                  • R Robert M.

                    @Robert-M
                    Using struct instead of QVector<QVariant> produced simpler and smaller code.
                    What is adventage of using QVector<QVariant> instead of struct?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #21

                    @Robert-M
                    A struct must contain a fixed number of named members with their own (quite possibly) different types.

                    A vector/array allows a dynamic number of elements each of which must be of the same type (even if that is QVariant, which itself allows values with different underlying types).

                    If your problem fits into the first case a struct is preferable, as seems to be the case here.

                    1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      This post is deleted!

                      R Offline
                      R Offline
                      Robert M.
                      wrote on last edited by
                      #22

                      @jsulm
                      I use other_options itself, not QVector<other_options>.

                      Pl45m4P 1 Reply Last reply
                      0
                      • R Robert M.

                        @jsulm
                        I use other_options itself, not QVector<other_options>.

                        Pl45m4P Offline
                        Pl45m4P Offline
                        Pl45m4
                        wrote on last edited by
                        #23

                        @Robert-M said in SIGSEGV in fromStdString:

                        other_options

                        If other_options is your struct with your data, you want to send to your dialog, it's fine. Nobody said it's not :)
                        The QVector would make it more variable


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        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