Results 1 to 10 of 10

Thread: Random value in a linedit

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2018
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Random value in a linedit

    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)
    Capture.PNG

    Then the .cpp and .h:

    .h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18. private:
    19. Ui::MainWindow *ui;
    20.  
    21. private slots:
    22. void Statut_Changed(int value);
    23. };
    24.  
    25. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 


    .cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void MainWindow::Statut_Changed(int value)
    17. {
    18. value = 50;
    19. ui->lineEdit->setText(value);
    20. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Random value in a linedit

    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

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Random value in a linedit

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Random value in a linedit

    Something like this :
    Qt Code:
    1. void MainWindow::Statut_Changed(int value)
    2. {
    3. ui->lineEdit->setText(QString::number(value));
    4. ui->Thermo->setValue(value);
    5. }
    To copy to clipboard, switch view to plain text mode 
    or change QLineEdit to QDoubleSpinBox and connect QDoubleSpinBox::valueChanged signal to QwtThermo::setValue slot.

  5. #5
    Join Date
    Feb 2018
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Random value in a linedit

    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 ?

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Random value in a linedit

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Feb 2018
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Random value in a linedit

    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

  8. #8
    Join Date
    Feb 2018
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Random value in a linedit

    up

    Do you have an example of program for this ?
    Please

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Random value in a linedit

    Do you have a connect() statement anywhere? Is anything calling Statut_Changed()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Random value in a linedit

    Quote Originally Posted by DynamX View Post
    After I called Statut_Changed() in .cpp like this :
    Qt Code:
    1. void MainWindow::Statut_Changed(int value)
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 
    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.

Similar Threads

  1. Random markers from nowhere.
    By Spitfire in forum Qwt
    Replies: 10
    Last Post: 3rd November 2011, 14:43
  2. Replies: 10
    Last Post: 3rd February 2011, 11:27
  3. Replies: 1
    Last Post: 7th April 2010, 16:26
  4. random
    By raphaelf in forum General Programming
    Replies: 9
    Last Post: 6th June 2007, 12:33

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
  •  
Qt is a trademark of The Qt Company.