Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problems with buttons
Forum Updated to NodeBB v4.3 + New Features

Problems with buttons

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 1.0k Views
  • 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.
  • P Offline
    P Offline
    patcs
    wrote on 8 Jun 2017, 09:40 last edited by
    #1

    Hi to everyone,

    I'm trying to do a program. I have a little problem with the buttons. I had three buttons and I want that when I press one of them save a string in a variable, but the string is going to be different depending on the button that you clicked. I need to do this because I have to save this string in a database.

    Could someone help me please? thank yoou!!

    E 1 Reply Last reply 8 Jun 2017, 11:59
    0
    • P patcs
      8 Jun 2017, 09:40

      Hi to everyone,

      I'm trying to do a program. I have a little problem with the buttons. I had three buttons and I want that when I press one of them save a string in a variable, but the string is going to be different depending on the button that you clicked. I need to do this because I have to save this string in a database.

      Could someone help me please? thank yoou!!

      E Offline
      E Offline
      Eeli K
      wrote on 8 Jun 2017, 11:59 last edited by
      #2

      @patcs It would be easier to answer if you could show the source code you have now.

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Pradeep Kumar
        wrote on 8 Jun 2017, 12:38 last edited by
        #3

        Hi,

        @patcs
        As u mentioned, u need to store string values to the database when u click on the all three pushbutton,

        1. what are the string values, where do u get the values,?
        2. if all the values are different, then store in 3 different variables, and then when clicked the respective button pass the variable to database.

        Thanks,

        Pradeep Kumar
        Qt,QML Developer

        1 Reply Last reply
        0
        • P Offline
          P Offline
          patcs
          wrote on 14 Jun 2017, 07:36 last edited by
          #4

          I could solve it with this code:

          void MainWindow::insertUser()
          {
          QString dni_usuario = ui->lineEditDNI->text();
          QString nombre_usuario = ui->lineEditNombre->text();
          QString apellido_usuario = ui->lineEditPrimerApellido->text();
          QString apellido2_usuario = ui->lineEditSegundoApellido->text();
          QString edad_usuario = ui->lineEditEdad->text();
          QString notas_usuario = ui->textEdit->toPlainText();
          int estres_usuario = ui->horizontalSlider->value();
          QString fecha_sesion = ui->dateEdit->text();
          QString hora_sesion = ui->timeEdit->text();

          QString duracion_sesion = "";
          if(ui->radioButton->isChecked()){
              duracion_sesion = ui->radioButton->text();
          }else if(ui->radioButton_2->isChecked()){
              duracion_sesion = ui->radioButton_2->text();
          }else if(ui->radioButton_3->isChecked()){
              duracion_sesion = ui->radioButton_3->text();
          }
          
          QString elementos_sesion = "";
          if(ui->checkBox->isChecked() && ui->checkBox_2->isChecked() && ui->checkBox_3->isChecked()){
              elementos_sesion = "Luces, Colores, Sonidos";
          
          }else if(ui->checkBox->isChecked() && ui->checkBox_2->isChecked()){
              elementos_sesion = "Luces, Colores";
          
          }else if(ui->checkBox->isChecked() && ui->checkBox_3->isChecked()){
              elementos_sesion = "Luces, Sonidos";
          
          }else if(ui->checkBox_2->isChecked() && ui->checkBox_3->isChecked()){
              elementos_sesion = "Colores, Sonidos";
          
          }else if(ui->checkBox->isChecked()){
              elementos_sesion = "Luces";
          
          }else if(ui->checkBox_2->isChecked()){
              elementos_sesion = "Colores";
          
          }else if(ui->checkBox_3->isChecked()){
              elementos_sesion = "Sonidos";
          
          }
          
          
          
          
          
          QString consulta;
          
          consulta.append("INSERT INTO usuarios( dni, nombre, apellido, apellido2,edad, notas, estres, valoracion, duracion, elementos, fecha, hora)"
                              "values(:dni, :nombre, :apellido, :apellido2, :edad , :notas, :estres , :valoracion, :duracion, :elementos, :fecha, :hora);");
          
          QSqlQuery insertar;
          insertar.prepare(consulta);
          
          insertar.bindValue(":dni", dni_usuario);
          insertar.bindValue(":nombre", nombre_usuario);
          insertar.bindValue(":apellido", apellido_usuario);
          insertar.bindValue(":apellido2", apellido2_usuario);
          insertar.bindValue(":edad", edad_usuario);
          insertar.bindValue(":notas", notas_usuario);
          insertar.bindValue(":estres", estres_usuario);
          insertar.bindValue(":valoracion", valoracion_sesion);
          insertar.bindValue(":duracion", duracion_sesion);
          insertar.bindValue(":elementos", elementos_sesion);
          insertar.bindValue(":fecha", fecha_sesion);
          insertar.bindValue(":hora", hora_sesion);
          
          
          if(insertar.exec())
          {
              qDebug()<<"El USUARIO se ha insertado correctamente.";
          
          }else{
              qDebug()<<"El USUARIO NO se ha insertado correctamente.";
              qDebug()<<"ERROR!"<<insertar.lastError();
          
          }
          

          }

          void MainWindow::on_buenaVal_clicked()
          {
          valoracion_sesion = "Buena";
          }

          void MainWindow::on_normalVal_clicked()
          {
          valoracion_sesion = "Normal";
          }

          void MainWindow::on_malaVal_clicked()
          {
          valoracion_sesion = "Mala";
          }

          1 Reply Last reply
          0

          1/4

          8 Jun 2017, 09:40

          • 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