Results 1 to 4 of 4

Thread: How to get a spinbox value to a variable ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2018
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How to get a spinbox value to a variable ?

    Hi everyone,
    I´m new to programming and Qt, but i loved the interface and I´m trying to learn and improve my skills.
    I received a task to create a simple interface that is composed of 4 spinboxes, 2 radio buttons, 2 checboxes and a command link button(RUN).
    I have to select the values on each one and when I press the RUN button it has to get all those values chosen and create a txt file, where each line is one of the values, this file will be later read by another program as a configuration file ini.
    I created variables that should receive these values and by the end are read by another function that creates the txt file.
    My problem is how to assign the values changed on the spinboxes and assign it to the variables. I can get the default values, when the interface initializes assigned to the variables, but when I select the values I want and click RUN nothing happens. I´m pretty sure it is something very simple, I just don’t know what. Can u give some idea what am I doing wrong?
    Thanks in advance.

    header code:

    #ifndef INTERFACE2_H
    #define INTERFACE2_H
    #include <QtGui>
    #include <QWidget>

    namespace Ui {
    class interface2;
    }

    class interface2 : public QWidget
    {
    Q_OBJECT

    public:
    explicit interface2(QWidget *parent = 0);
    ~interface2();

    private:
    Ui::interface2 *ui;

    qint64 number_traces;
    qint64 trace_samples;
    qreal sampling_rate;
    qint64 wavelet_freq;
    qint64 polarity;
    qint64 noise;
    qint64 standard_reflec;

    void write();


    private slots:
    void on_RUN_clicked();
    };

    #endif // INTERFACE2_H

    cpp code

    #include "interface2.h"
    #include "ui_interface2.h"
    #include <QtCore/QString>
    #include <QtCore/QFile>
    #include <QtCore/QTextStream>
    #include <QMessageBox>

    interface2::interface2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::interface2)

    {

    ui->setupUi(this);
    on_RUN_clicked();
    write();

    }

    interface2::~interface2()
    {
    delete ui;
    }

    void interface2:n_RUN_clicked()
    {

    number_traces = ui->traces->value();
    trace_samples = ui->samples->value();
    sampling_rate = ui->rate->value();
    wavelet_freq = ui->freq->value();

    {
    if(ui->reflectivity->isChecked())/*refletividade padrao*/
    {
    standard_reflec= 1;
    }
    else
    {
    standard_reflec= 0;
    }
    }

    {
    if(ui->Noise->isChecked())/*introduzir ruido*/
    {
    noise= 1;
    }
    else
    {
    noise= 0;
    }
    }

    {
    if(ui->negative->isChecked())/*polaridade negativa*/
    {
    polarity=-1;
    }

    }

    {
    if(ui->positive->isChecked())/*polaridade positiva*/
    {
    polarity=1;
    }
    }
    }


    void interface2::write()
    {

    QString outputFilename = "sismica1.ini";
    QFile outputFile(outputFilename);
    outputFile.open(QIODevice::WriteOnly|QIODevice::Te xt);

    /* Check it opened OK */
    if(!outputFile.isOpen())
    {
    QMessageBox::warning(this,tr("Sismica"),tr("- Error, unable to open sismica1.ini for output"));
    //return 1;
    }

    /* Point a QTextStream object at the file */
    QTextStream outStream(&outputFile);

    /* Write the line to the file */
    outStream << "////////////////////////////////////////////////////////////////////////////////////"<<endl
    << "// INITIALIZATION FILE FOR SISMICA1 PROGRAM //"<<endl
    << "// //"<<endl
    << "// This is the initialization file, it is not required for running the program //"<<endl
    << "// but any change on the parameters MUST be done trough it, otherwise pre-loaded //"<<endl
    << "// values will be used. //" <<endl
    << "// //"<<endl
    << "// //"<<endl
    << "// It MUST be on the same directory as sismica1.exe //"<<endl
    << "// //"<<endl
    << "// The file generated will be named: traços.txt, it will contain the convolution //"<<endl
    << "// results. //"<<endl
    << "// //"<<endl
    << "// //"<<endl
    << "// IMPORTANT : //"<<endl
    << "// ========== //"<<endl
    << "// //"<<endl
    << "// Do not change the amount of lines in this file, except, if you include new para//"<<endl
    << "// meters on the source code; //"<<endl
    << "// DO NOT change the parameters order; //"<<endl
    << "// Use dot(.) as decimal separator; //"<<endl
    << "// There MUST NOT be any blank spaces or any non printable charactere. //"<<endl
    << "// //"<<endl
    << "// //"<<endl
    << "// The parameters are separated by a new line character, so everything along the //"<<endl
    << "// line below this header, will be considered as parameter. //"<<endl
    << "// //"<<endl
    << "// //"<<endl
    << "// Parameters //"<<endl
    << "// ========== //"<<endl
    << "// //"<<endl
    << "// Impedance file name //"<<endl
    << "// Number of traces (0 use all the traces on file) //"<<endl
    << "// Trace samples amount //"<<endl
    << "// Sampling rate //"<<endl
    << "// Wavelet peak frequency //"<<endl
    << "// Polarity //"<<endl
    << "// Flag indicating the use of noise //"<<endl
    << "// Flag indicating the use of standard reflectivity model //"<<endl
    << "// //"<<endl
    << "// Credits: Carlos da S. Claudino /Flavio Mesquita //"<<endl
    << "///////////////////////////////////////////////////////////////////////////////////"<<endl
    << "Impedancia.txt"<<"\n"
    << number_traces<<"\n"
    << trace_samples<<"\n"
    << sampling_rate/1000<<"\n"
    << wavelet_freq<<"\n"
    << polarity<<"\n"
    << noise<<"\n"
    << standard_reflec<<"\n";

    /* Close the file */
    outputFile.close();
    }
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. Replies: 2
    Last Post: 19th October 2017, 23:25
  2. how connection variable in functin with spinBox
    By Sergey19 in forum Qt Programming
    Replies: 22
    Last Post: 9th August 2010, 09:13
  3. Getting the value from a spinbox
    By X-man in forum Newbie
    Replies: 14
    Last Post: 28th September 2007, 01:27
  4. spinbox
    By mickey in forum Newbie
    Replies: 5
    Last Post: 26th July 2006, 19:09
  5. spinbox
    By mickey in forum Newbie
    Replies: 2
    Last Post: 22nd May 2006, 08:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.