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. Inserting spinbox values into a QString().arg()
Forum Updated to NodeBB v4.3 + New Features

Inserting spinbox values into a QString().arg()

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 900 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.
  • J Offline
    J Offline
    joshuagahan
    wrote on 21 Jun 2016, 07:33 last edited by
    #1

    Thank You everyone for help with my previous problem, I've encountered a new problem however:

    void MainWindow::on_pushButton_clicked()

    {
    const auto text = ui->comboBox->currentText();

    if (text=="Add Nothing")
    {
        ui->plainTextEdit->insertPlainText( QString("%{selected|repeating_spell-1_$0_spell}").arg(text));
    }
    
    /* What I'm trying to do is below this line.  The above compiles and functions perfectly.  
     if (text=="Add Nothing")
    {
        ui->plainTextEdit->insertPlainText( QString("%{selected|repeating_spell-%s_$%s_spell}", spinbox1 value, spinbox2 value).arg(text));
    }
    
          I'm aware the above commented code is incorrect, but I'm not quite sure how to proceed.  Essentially this program takes a selection from the combo box and upon hitting the pushbutton writes it to the editor.  Now in the case of %{selected|repeating_spell-1_$0_spell, the spell-1 defines the spell level and the $0 defines the spell # at that level (overall this program is meant to write macros).  Given the range of possibilities I would end up with a combo box of 50+ items, too many..  What I'm trying to do is insert %{selected|repeating_spell-x_$y_spell where x and y are integers pulled from spinboxes.
    */
    

    }

    Thank you for the help everyone. I'm very new to Qt and not much more experienced in c++, I really appreciate the help.

    J 1 Reply Last reply 21 Jun 2016, 07:44
    0
    • J joshuagahan
      21 Jun 2016, 07:33

      Thank You everyone for help with my previous problem, I've encountered a new problem however:

      void MainWindow::on_pushButton_clicked()

      {
      const auto text = ui->comboBox->currentText();

      if (text=="Add Nothing")
      {
          ui->plainTextEdit->insertPlainText( QString("%{selected|repeating_spell-1_$0_spell}").arg(text));
      }
      
      /* What I'm trying to do is below this line.  The above compiles and functions perfectly.  
       if (text=="Add Nothing")
      {
          ui->plainTextEdit->insertPlainText( QString("%{selected|repeating_spell-%s_$%s_spell}", spinbox1 value, spinbox2 value).arg(text));
      }
      
            I'm aware the above commented code is incorrect, but I'm not quite sure how to proceed.  Essentially this program takes a selection from the combo box and upon hitting the pushbutton writes it to the editor.  Now in the case of %{selected|repeating_spell-1_$0_spell, the spell-1 defines the spell level and the $0 defines the spell # at that level (overall this program is meant to write macros).  Given the range of possibilities I would end up with a combo box of 50+ items, too many..  What I'm trying to do is insert %{selected|repeating_spell-x_$y_spell where x and y are integers pulled from spinboxes.
      */
      

      }

      Thank you for the help everyone. I'm very new to Qt and not much more experienced in c++, I really appreciate the help.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 21 Jun 2016, 07:44 last edited by jsulm
      #2

      @joshuagahan Why not just use QSpinBox::value() and replace %s with %1 and %2? QString::arg() will convert int returned from QSpinBox::value() to string:

      ui->plainTextEdit->insertPlainText( QString("%{selected|repeating_spell-%1_$%2_spell}").arg(spinbox1.value()).arg(spinbox2.value()));
      }
      

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

      J 1 Reply Last reply 21 Jun 2016, 07:48
      1
      • J jsulm
        21 Jun 2016, 07:44

        @joshuagahan Why not just use QSpinBox::value() and replace %s with %1 and %2? QString::arg() will convert int returned from QSpinBox::value() to string:

        ui->plainTextEdit->insertPlainText( QString("%{selected|repeating_spell-%1_$%2_spell}").arg(spinbox1.value()).arg(spinbox2.value()));
        }
        
        J Offline
        J Offline
        joshuagahan
        wrote on 21 Jun 2016, 07:48 last edited by
        #3

        @jsulm

        I'll try to see if I can get that to work, I was trying to do something similar to that. Thanks for the help again jsulm, I'm pretty damn new to this (most of my programming experience is in c with arduinos and I'm very very new to GUI programming). thanks again.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          joshuagahan
          wrote on 21 Jun 2016, 08:12 last edited by
          #4

          code works perfectly Thank you!

          1 Reply Last reply
          0

          1/4

          21 Jun 2016, 07:33

          • Login

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