Qt Forum

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

    Unsolved Appending text to PlainTextedit using combo boxes and buttons

    General and Desktop
    3
    6
    915
    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.
    • joshuagahan
      joshuagahan last edited by

      New to QT. I'm writing a program that writes macros for a website I play online. Essentially what I want is a combobox that when I press the pushbutton, reads the current combobox selection and appends a snippet of text into the TextEdit.

      using pseudo code:

      if pushbutton is clicked():
      {
      read combo box selection
      append comboboxselection(string) to Text edit
      }

      combobox()
      {
      string sometext
      if(combobox selection is "1st cantrip")
      {
      text = "%{selected|repeating_spell-cantrip_$0_spell}"
      }
      }

      joshuagahan 1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by

        Hi, and welcome to the Qt forum!

        void MainWindow::on_pushButton_clicked()
        {
            const auto text = ui->comboBox->currentText();
            if (text=="First Item") {
                ui->textEdit->append( QString("%1 something").arg(text) );
            } else if (text=="Second Item") {
                ui->textEdit->append( QString("%1 something else").arg(text) );
            } else {
                ui->textEdit->append( QString("%1 default").arg(text) );
            }
        }
        
        joshuagahan 1 Reply Last reply Reply Quote 1
        • joshuagahan
          joshuagahan @Guest last edited by

          @Wieland thank you so much!

          1 Reply Last reply Reply Quote 0
          • joshuagahan
            joshuagahan @joshuagahan last edited by joshuagahan

            @Wieland

            Follow on Question: After implementing the code: nothing happened, I went the moc file where

            void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
            {
            if (_c == QMetaObject::InvokeMetaMethod) {
            MainWindow *_t = static_cast<MainWindow *>(_o);
            Q_UNUSED(_t)
            switch (_id) {
            case 0: _t->on_deleteThisComboBox_currentTextChanged((reinterpret_cast< const QString()>(_a[1]))); break;
            case 1: _t->on_deletThisPlainTextEdit_destroyed(); break;
            case 2:_t->on_deletThisPushButton_clicked(); break;
            default: ;
            }
            }
            }

            in case 2: The text is added to the plaintextbox automatically whenever I change the combobox selection, also clicking the pushbutton has no effect on appending text whatsoever, despite the code being inside the code:

            void MainWindow::on_deletThisPushButton_clicked()
            {
            const auto text = ui->deleteThisComboBox->currentText();
            if (text=="1st Cantrip") {
            ui->deletThisPlainTextEdit->appendPlainText( QString("something").arg(text) );
            } else if (text=="2nd Cantrip") {
            ui->deletThisPlainTextEdit->appendPlainText( QString("something else").arg(text) );
            } else {
            ui->deletThisPlainTextEdit->appendPlainText( QString("default").arg(text) );
            }
            }

            1 Reply Last reply Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion last edited by

              Sorry, it is not really clear what the problem now is. @Wieland provided you the code you have to put into your slot which is connected to the clicked signal of the button. Did you connect the signal and slot?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              joshuagahan 1 Reply Last reply Reply Quote 0
              • joshuagahan
                joshuagahan @jsulm last edited by

                @jsulm Its been working fine this is solved. I have a project where I experiment in and got a lot of my code messed up. When I tried this code in a fresh project, it worked perfectly. Thanks.

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