I’m working on Visual studio (c++) and I’m using Qt along with OpenCV.
What I want to do is create a window where I can input several values that will be used in an algorithme later. These variables are double and int type.
I’ve looked at the Qt doc and on the internet but I didn’t find a proper way to do so. I’m also not looking for a dialog box to pop up and ask the user to input values, just a window with several fields to type my values and update them.
Any help would be appreciated, thanks
EDIT:
I’m now using a QDoubleSpinBox to input a double value and a button to update and print the value in a console.
I’ve created a class for my button to be able to use custom SLOTS in main.h :
class MyButton : public QWidget
{
Q_OBJECT
public:
MyButton();
public slots:
void updateValue(QDoubleSpinBox* input);
};
And this is the main.cpp:
#include "main.h"
#include <QtGui>
#include <iostream>
using namespace std;
double value;
MyButton::MyButton() : QWidget()
{
QPushButton *update = new QPushButton("update",this);
connect(update, SIGNAL(clicked()), this, SLOT(updateValue(QDoubleSpinBox)));
}
void MyButton::updateValue(QDoubleSpinBox *input)
{
input->update();
value = input->value();
cout<<value;
}
Now I’m not sure what to write in the ‘main’ function to use that to create the button. Here is my ‘main’ function so far:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
QDoubleSpinBox *input = new QDoubleSpinBox();
input->setValue(5.00);
QVBoxLayout *vbox1 = new QVBoxLayout;
vbox1->addWidget(input);
window.setLayout(vbox1);
window.resize(800,600);
window.show();
window.setWindowTitle(QApplication::translate("toplevel", "Top-level widget"));
return app.exec();
}
To solve your task you should know the following topics:
1. which widgets can be used to get input from a user(most of them were already stated);
2. SIGNALS & SLOTS in Qt (using them you can assign values which were provided to a widget to your variables).
As that topics are rather volumable I advice you to refer to Qt documentation (use Qt assistant for example), as now you know for what information to search it will be easier for you to solve you task