Qt Help

I am new to Qt. While learning Qt GUI programming I'm also playing around with it. With the code below, I want to display the number that the user has entered into a spinner (QSpinBox) when a button has been pressed (QPushButton). I display the number using a label (QLabel).

But, instead when I enter a number in and press the button, nothing happens. I try to set the label as the value of the spinner when the button is pressed, but it isn't changing the label.

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <QApplication>
#include <QHBoxLayout>
#include <QSpinBox>
#include <QLabel>
#include <QPushButton>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    
    QWidget *main = new QWidget;
    main->setWindowTitle("Test");
    
    QSpinBox *spinner = new QSpinBox;
    QPushButton *button = new QPushButton("Go");
    QLabel *label = new QLabel("0");
    
    label->setAlignment(Qt::AlignCenter);
    spinner->setRange(0, 1000000000);
    spinner->setValue(0);

    // Here I try to set the label as value of spinner
    QObject::connect(button, SIGNAL(clicked()), label,
    SLOT(setNum(spinner->value)));
    
    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(spinner);
    layout->addWidget(button);
    layout->addWidget(label);
    
    main->setLayout(layout);
    main->show();
    
    return app.exec();
}
Last edited on
closed account (48T7M4Gy)
Qt doesn't lend itself to manual programming for beginners especially the way you are doing it with apparently just a main() function and a single file.

There are numerous associated files that keep track of GUI's, widgets their properties, sizes, layout and all the rest. Your file creates objects but nothing else.

Why aren't you using Qt Creator? It's free and it works.
I do use Qt Creator... on my computer. But, I'm using C4droid on my mobile device. With it I can make my Qt programs into apps.

But, I know you can create mobile apps with Qt Creator as well. It's just that it seems complicated since I have to install and setup Android SDK, NDK, Java SE Development Kit, and Apache Ant.

I'm willing to program Qt applications for PC and mobile if I can learn how. Some help?
Last edited on
closed account (48T7M4Gy)
QT says it's simple. I'll take your word for it if they've got it wrong because I haven't tried.

Beyond that FWIW ... https://www.qt.io/mobile-app-development/
Topic archived. No new replies allowed.