Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7787257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:36:22+00:00 2026-06-01T20:36:22+00:00

I am a newbie at Qt programming and I have some issues with the

  • 0

I am a newbie at Qt programming and I have some issues with the code below. I wanted to create a simple two button application with one label. One button is for positive increment one, and the other button is for decrement one. The label should be updated once I click the plus or minus button. But it doesn’t work. Any ideas why the code doesn’t work? I get a compiler error for an element function void. But the error message is rather unspecific.

I checked the internet (intensive google search and also here on stackoverflow) for a solution but I could not find one. I very much appreciate any direct help or linkage to other websites / links. Please let me know in case I should rephrase the question or add some more information. Thanks for your time. Stefan

#include "widget.h"

int counter = 0;

Widget::Widget(QWidget *parent) :
QWidget(parent)
{
    setFixedSize(200, 120);

    QPushButton *Plus = new QPushButton(tr("+"), this);
    Plus -> setGeometry(62, 40, 75, 30);
    Plus -> setFont(QFont("Times", 10, QFont::Bold));

    QPushButton *Minus = new QPushButton(tr("-"), this);
    Minus -> setGeometry(62, 40, 75, 30);
    Minus -> setFont(QFont("Times", 10, QFont::Bold));

    QLabel *MyLabel = new QLabel();
    MyLabel ->setAlignment(Qt::AlignCenter);
    MyLabel ->setGeometry(62, 40, 75, 30);
    MyLabel ->setNum(counter);

    QVBoxLayout *layout = new QVBoxLayout;
    layout ->addWidget(MyLabel);
    layout ->addWidget(Plus);
    layout ->addWidget(Minus);
    setLayout(layout);


    connect(Plus, SIGNAL(clicked()), this, SLOT(myClickPlus()));
    connect(Minus, SIGNAL(clicked()), this, SLOT(myClickMinus()));
}

void Widget::myClickPlus(){
    counter ++;
    qDebug("Das ist der Plus-Button");
    MyLabel -> setNum(counter);
}

void Widget::myClickMinus()
{
    counter --;
    qDebug("Das ist der Minus-Button");
    MyLabel ->setNum(counter);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:36:24+00:00Added an answer on June 1, 2026 at 8:36 pm

    The MyLabel that you are creating in the Widget’s constructor is a local variable. The MyLabel that you are using in the myClickPlus and myClickMinus member functions is a member variable. So they are completely different instances.

    If your code compiles, then this change in the Widget’s constructor will probably fix the problem:

    QLabel *MyLabel = new QLabel(); // create local QLabel
    

    –>

    MyLabel = new QLabel();  // create member QLabel
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a complete Android programming newbie. I have completed some tutorial examples like
I'm a newbie here and in XNA programming, but I have some skills in
Hi I am a newbie to iPhone programming. I have been looking at some
I am a newbie to the programming world. I have experiences of developing simple
I am a newbie with iphone programming. I need some help with this code.
Pardon the dumb newbie question here; web programming isn't my forte... (blush) I have
I'm a newbie in C programming. I have this issue that I don't understand.
I'm a newbie to programming and need some help with the set of fixers
I am a newbie to programming and need some help with the basics. I
I'm quite a newbie to Cocoa & Mac programming. I have a WebView and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.