Results 1 to 2 of 2

Thread: qdoublevalidator and plaintext

  1. #1
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11

    Default qdoublevalidator and plaintext

    Hi,
    Please, I am a very beginner in qt and this must be a stupid question. I am using a plainTextEdit box to input a list of double precision numbers. Is it possible to use QDoubleValidator to forbid the input of other characters (e.g. letters, symbols #$%?, etc. ) into the TextEdit box? In the following I put the c++ code.
    Thank you,
    Daniel
    -------------------------------------------------

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <stdio.h>
    #include <math.h>
    #include <QMessageBox>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

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

    void MainWindow::on_pushButton_released()
    {

    //double x;
    QStringList x;
    int i,j,k=0;
    //int i=1; int j;
    //x=ui->plainTextEdit->toPlainText().toDouble();
    // QDoubleValidator *x;
    x = ui->plainTextEdit->toPlainText().split("\n");
    i=x.size();
    double y[i],x_medio=0.0,sigma2=0.0,sigma;
    for (j=0;j<i;j++){
    y[j]=x.at(j).toDouble();
    }
    for (j=0;j<i;j++)
    {
    x_medio=y[j]/i+x_medio;
    }
    for(j=0;j<i;j++)
    {
    sigma2=sigma2+pow(y[j]-x_medio,2.0)/(i*(i-1.0));

    }
    sigma=sqrt(sigma2);
    ui->label->setNum(x_medio);
    ui->label_2->setNum(sigma);
    ui->plainTextEdit->clear();
    }

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    456
    Thanks
    10
    Thanked 61 Times in 59 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qdoublevalidator and plaintext

    Hi, I think the easier and more standard way would be to use a QDoubleSpinBox instead of a restricted text edit field.

    Ginsengelf

  3. The following user says thank you to Ginsengelf for this useful post:

    daniel_muller (7th October 2013)

Similar Threads

  1. plainText object and greek
    By funkybomber in forum Newbie
    Replies: 4
    Last Post: 4th May 2010, 08:43
  2. QDoubleValidator
    By gt.beta2 in forum Newbie
    Replies: 5
    Last Post: 5th February 2009, 20:44
  3. QDoubleSpinBox and QDoubleValidator
    By George Neil in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2008, 01:36
  4. QDoubleValidator
    By cristiano in forum Qt Programming
    Replies: 7
    Last Post: 19th January 2007, 22:10
  5. Extract method on plaintext with QRegExp
    By jlbrd in forum Qt Programming
    Replies: 1
    Last Post: 2nd July 2006, 14:38

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.