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



  • 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.


  • Moderators

    @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()));
    }
    


  • @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.



  • code works perfectly Thank you!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.