PDA

View Full Version : Random value in a linedit



DynamX
23rd February 2018, 11:35
hello,

So I explain, I did several tests to display a random value in a LineEdit Here is what the window looks like: (I'm with QMainWindow)
12779

Then the .cpp and .h:

.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

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

private:
Ui::MainWindow *ui;

private slots:
void Statut_Changed(int value);
};

#endif // MAINWINDOW_H


.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

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

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

void MainWindow::Statut_Changed(int value)
{
value = 50;
ui->lineEdit->setText(value);
}

I would like to display the desired value in the LineEdit and once done, create a connection between QwtTHermo and LineEdit.
For example, by setting the value 50, I would like this value to be displayed in the lineEdit and also displayed in QwtThermo

Do you have an idea ?
Already to display the value in lineEdit

Thank you for your help

ChristianEhrlicher
23rd February 2018, 16:04
QLineEdit::setText() takes a QString, value is an integer. So I would try to convert the integer to a string. For example: http://doc.qt.io/qt-5/qstring.html#number

d_stranz
23rd February 2018, 17:05
And QwtThermo:: setValue( double value ) (along with QwtThermo:: setScale( double lower, double upper ), inherited from QwtAbstractScale) will let you set the thermometer range limits and current value.

Lesiok
23rd February 2018, 17:05
Something like this :
void MainWindow::Statut_Changed(int value)
{
ui->lineEdit->setText(QString::number(value));
ui->Thermo->setValue(value);
}or change QLineEdit to QDoubleSpinBox and connect QDoubleSpinBox::valueChanged signal to QwtThermo::setValue slot.

DynamX
24th February 2018, 11:41
This does not work,
Finally by launching the compilation nothing happens, the chosen value does not appear in the lineEdit.

I would like to start by taking a value that we choose in the .cpp and then with a QString, text () or setText () or whatever, the chosen value appears in the lineEdit.
Once the value appears, it is necessary to link the lineEdit and the QwtThermo so that the value in the lineEdit also appears in the QwtThermo (50 in lineEdit so 50 in QwtThermo).

I tested your program but nothing appears in lineEdit, even choosing 50 as a value.

Do you understand what I've said, do you have another solution ?

d_stranz
24th February 2018, 16:12
Are you actually calling your "Statut_Changed()" method from anywhere? Just because you write a method in your main window class doesn't mean it gets executed. If you aren't calling this method either directly or through a signal linked to that slot, then of course nothing will happen.

DynamX
24th February 2018, 21:35
I've declared Statut_Changed() in .h, in private slots like this :

private slots:
void Statut_Changed(int value);

After I called Statut_Changed() in .cpp like this :

void MainWindow::Statut_Changed(int value)
{
}

What is your solution ? Is it the solution or i've completaly wrong

DynamX
25th February 2018, 11:42
up

Do you have an example of program for this ?
Please

wysota
25th February 2018, 13:24
Do you have a connect() statement anywhere? Is anything calling Statut_Changed()?

Lesiok
25th February 2018, 16:52
After I called Statut_Changed() in .cpp like this :
void MainWindow::Statut_Changed(int value)
{
}
What is your solution ? Is it the solution or i've completaly wrong

This is not a "call of function/method" - this is a declaration of function/method body. Qt is a C++ library and You need to know C++ to use Qt.