You are not logged in.

jchae14

Beginner

  • "jchae14" is male
  • "jchae14" started this thread

Posts: 2

Location: Champaign, IL

Occupation: Student

  • Send private message

1

Wednesday, September 28th 2011, 6:33pm

My label doesn't change when I click Button... please help me!

#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QWidget *window = new QWidget;
QHBoxLayout *mainLayout = new QHBoxLayout;
QVBoxLayout *sideMenu = new QVBoxLayout;
QVBoxLayout *board = new QVBoxLayout;

QLabel *status = new QLabel("Let the game Start");

sideMenu->addWidget(status);

QPushButton *quit = new QPushButton("Quit");

QObject::connect(quit, SIGNAL(clicked()), &app, SLOT(quit()));

sideMenu->addWidget(quit);


QHBoxLayout *layout1 = new QHBoxLayout;
QHBoxLayout *layout2 = new QHBoxLayout;
QHBoxLayout *layout3 = new QHBoxLayout;


QPushButton *button11 = new QPushButton("1");
QPushButton *button12 = new QPushButton("2");
QPushButton *button13 = new QPushButton("3");

QObject::connect(button11, SIGNAL(clicked()), status, SLOT(setText("Button 1 is clicked")));
QObject::connect(button12, SIGNAL(clicked()), status, SLOT(setText("Button 2 is clicked")));
QObject::connect(button13, SIGNAL(clicked()), status, SLOT(setText("Button 3 is clicked")));

.
.
.
.
.
.
}


I have seen other threads regarding the same issue but I can't apply that solution to my problem.

2

Wednesday, September 28th 2011, 7:17pm

the error message at runtime is quite clear....

Object::connect: No such slot QLabel::setText("Button 1 is clicked")


Source code

1
2
3
4
  QSignalMapper mapper; // you probably need to put on the heap
  mapper.setMapping(button11, "butt 1 clicked");
  QObject::connect(&mapper, SIGNAL(mapped(const QString&)), status, SLOT(setText(const QString&)));
  QObject::connect(button11, SIGNAL(clicked()), &mapper, SLOT(map()));
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

This post has been edited 1 times, last edit by "Amleto" (Sep 28th 2011, 7:28pm)


jchae14

Beginner

  • "jchae14" is male
  • "jchae14" started this thread

Posts: 2

Location: Champaign, IL

Occupation: Student

  • Send private message

3

Wednesday, September 28th 2011, 11:17pm

#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QWidget *window = new QWidget;
QHBoxLayout *mainLayout = new QHBoxLayout;
QVBoxLayout *sideMenu = new QVBoxLayout;
QVBoxLayout *board = new QVBoxLayout;

QLabel *status = new QLabel("Let the game Start");

sideMenu->addWidget(status);

QPushButton *quit = new QPushButton("Quit");

QObject::connect(quit, SIGNAL(clicked()), &app, SLOT(quit()));

sideMenu->addWidget(quit);


QHBoxLayout *layout1 = new QHBoxLayout;
QHBoxLayout *layout2 = new QHBoxLayout;
QHBoxLayout *layout3 = new QHBoxLayout;


QPushButton *button11 = new QPushButton("1");
QPushButton *button12 = new QPushButton("2");
QPushButton *button13 = new QPushButton("3");

QObject::connect(button11, SIGNAL(clicked()), status, SLOT(setText("Button 1 is clicked")));
QObject::connect(button12, SIGNAL(clicked()), status, SLOT(setText("Button 2 is clicked")));
QObject::connect(button13, SIGNAL(clicked()), status, SLOT(setText("Button 3 is clicked")));


QPushButton *button21 = new QPushButton("4");
QPushButton *button22 = new QPushButton("5");
QPushButton *button23 = new QPushButton("6");

QPushButton *button31 = new QPushButton("7");
QPushButton *button32 = new QPushButton("8");
QPushButton *button33 = new QPushButton("9");




layout1->addWidget(button11);
layout1->addWidget(button12);
layout1->addWidget(button13);


layout2->addWidget(button21);
layout2->addWidget(button22);
layout2->addWidget(button23);

layout3->addWidget(button31);
layout3->addWidget(button32);
layout3->addWidget(button33);

board->addLayout(layout1);
board->addLayout(layout2);
board->addLayout(layout3);

mainLayout->addLayout(board);
mainLayout->addLayout(sideMenu);

window->setLayout(mainLayout);

window->show();

return app.exec();

}


This is my entire code

4

Wednesday, September 28th 2011, 11:30pm

great. now read my first post. the one where the answer is.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.