Take the 2-minute tour ×

I have a simple application, that consists of one line edit, where user writes an answer and a confirmation button. If the answer was correct, I'd like to draw a simple figure (green / red circle for example). I have three source files - main, form (here I connect the signal from button with answer from lineedit and determine if answer is correct) and figureWidget, where i'd like to draw my figure. My problem is, that I can't find out how to connect the signal from "form" with my figureWidget (especially what with what and where :-) ) Any hints? file form.cpp:

#include <QtCore>
#include "ui_untitled.h"
#include "Form.h"
#include "figureWidget.h"

Form::Form(QWidget * parent, Qt::WindowFlags f) : QWidget ( parent,f ) {

connect(ui.pushButton, SIGNAL(buttonPressed()), this, SLOT(checkAnswer()))
 //this checks if answer is correct after pushing button
connect(this,SIGNAL(correctness(QString)),ui.figureWidget, SLOT(drawFigure(QString)));
  //I expect signal from this class (here I check the answer), and draw the circle in figureWidget

void Form::checkAnswer() {
 if (ui.lineEdit == "1") emit correctness(QString("right");
  else emit correctness(QString("false") 

then I have the figureWidget.cpp:

#include <QtGui>
#include <iostream>
#include "figureWidget.h"
figureWidget::figureWidget(QWidget* parent) : QWidget(parent) {

figureWidget::~figureWidget() {

void figureWidget::drawFigure(QString newVal) {
 if (newVal == correctVal) 

void figureWidget::paintEvent(QPaintEvent* ) {
   QPainter painter(this);
   painter.drawEllipse(0, 0, 10, 10);

in debug i get: No such slot QWidget::drawFigure(QString) in ...

share|improve this question
doc.qt.digia.com/qt/signalsandslots.html - I'm sorry but your question is very vague. You connect a signal to a slot, and that's it. If you've got code that doesn't work as you expect it to, please show that code so that people can help you figure out what's wrong. –  Mat Oct 7 '12 at 12:14
I'm sorry, I was hoping that someone could figure out what I mean (maybe common problem). Anyway, I added the code –  Johnzzz Oct 7 '12 at 12:45
Where is checkAnswer? Where to you emit the correctness signal? –  Mat Oct 7 '12 at 12:46
checkAnswer is in form.cpp (where are the connects). This slot also emits the correctness signal –  Johnzzz Oct 7 '12 at 12:49
I don't understand your problem then. Are the slots not being called? –  Mat Oct 7 '12 at 12:51
show 5 more comments

1 Answer

I think you can try this:

connect(this,SIGNAL(correctness(QString)),this, SLOT(drawFigure(QString)));

void Form::drawFigure(QString val)

But how could figureWidget appears after 'ui->'??? You cannot draw it on the UI statically.

share|improve this answer
add comment

Your Answer


