Results 1 to 5 of 5

Thread: How to use a 'Knob'?

  1. #1
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default How to use a 'Knob'?

    Hello

    I try to use the 'Knob'. I turn the 'Knob' but the value of the label isn't changed.

    66.png

    Knob.pro
    Qt Code:
    1. SOURCES += \
    2. main.cpp \
    3. mainwindow.cpp
    4.  
    5. HEADERS += \
    6. mainwindow.h
    7.  
    8. QWT_LOCATION = c:/Qwt-6.0.2
    9. INCLUDEPATH += $${QWT_LOCATION}/include
    10. LIBS = -L$${QWT_LOCATION}/lib \
    11. -lqwt
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. MainWindow mw;
    9. mw.show();
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

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

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <qwt_knob.h>
    3. #include <QVBoxLayout>
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. MainWindow::MainWindow(QWidget *parent) :
    8. QMainWindow(parent)
    9. {
    10. knob = new QwtKnob;
    11. label = new QLabel(QString::number(knob->value()));
    12.  
    13. QVBoxLayout *mainLayout = new QVBoxLayout;
    14. mainLayout->addWidget(label, 0, Qt::AlignCenter);
    15. mainLayout->addWidget(knob);
    16.  
    17. QWidget *window = new QWidget;
    18. window->setLayout(mainLayout);
    19.  
    20. setCentralWidget(window);
    21.  
    22. this->setWindowTitle(tr("Knob"));
    23.  
    24. connect(knob, SIGNAL(valueChanged(double)), label, SLOT(setValueOfLabel(double )));
    25. }
    26.  
    27. void MainWindow::setValueOfLabel(double value)
    28. {
    29. label->setText(QString::number(value));
    30. }
    To copy to clipboard, switch view to plain text mode 

    Ivan

    Thanks

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

    Default Re: How to use a 'Knob'?

    setValueOfLabel() is defined in MainWindow and not QLabel. Surely you received a runtime warning about non-existing slot.
    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.


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

    8Observer8 (1st March 2013)

  4. #3
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to use a 'Knob'?

    Thank you

    Qt Code:
    1. connect(knob, SIGNAL(valueChanged(double)), this, SLOT(setValueOfLabel(double)));
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Sep 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to use a 'Knob'?

    Hi,
    I have tried the similar knob, and I have added the QWT_LOCATION as /home/user/QWT/qwt-6.0.3,where I have downloaded the qwt package.
    Error was;

    mainwindow.cpp:15: error: undefined reference to `QwtKnob::QwtKnob(QWidget*)'

    I think, my code can not get the QWtKnob class.

    My question is that whether I need to run the qwt project before use it into my program?

    Thanks
    Warren

  6. #5
    Join Date
    Sep 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to use a 'Knob'?

    Hi all,
    After I have installed the qwt package. I could successfully compile. Since I am the beginner I tried the above program which is successfully compiled. Somehow when I try to build, It show some run time error as shown below;

    ERRROR: The program has unexpectedly finished.

    In DebugMode:

    The inferior stopped because it received a signal from the operating system.

    Signal name :
    SIGSEGV
    Signal meaning :
    Segmentation fault

    Looks like, memeory issue. Could any one help me out.

    Thanks

Similar Threads

  1. QWT::Knob with the logarithmic scale
    By hack006 in forum Qwt
    Replies: 1
    Last Post: 2nd April 2011, 17:57
  2. QWT 5.2.0. Label on knob.
    By dima154 in forum Newbie
    Replies: 1
    Last Post: 11th October 2009, 10:40
  3. How to different Scale and Values in Knob
    By Doug Broadwell in forum Qwt
    Replies: 1
    Last Post: 23rd January 2009, 07:52

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.