Important: Please read the Qt Code of Conduct -

QObject::connect: No such slot QApplication::checkText()

  • Hey all!

    I am trying to build 2 buttons. With "Quit" you quit the Program , but if you click in " Clicke me" or "Info" it should open a Label with "Hello world"
    But I get the error: QObject::connect: No such slot QApplication::checkText()

    this is my code:


    #ifndef WINDOW_H
    #define WINDOW_H
    #include <QtGui>
    #include <QWidget>

    class QPushButton;
    class checkText;
    class Window : public QWidget
    explicit Window(QWidget *parent = 0);

    void QApplication();
    private slots:

    void checkText();


    QPushButton *m_button;


    #endif // WINDOW_H


    #include <QApplication>
    #include <QPushButton>
    #include "window.h"
    #include <QLabel>
    #include <QtGui>

    int main(int argc, char **argv)
    QApplication app (argc, argv);
    int)), progressBar, SLOT (setValue(int)));

    Window window;;
    window.setFixedSize(100, 80);

    QPushButton *buttonInfo = new QPushButton("Info", &window);
    buttonInfo->setGeometry(10, 10, 80, 30);
    QObject::connect(buttonInfo,SIGNAL(clicked()), qApp, SLOT(checkText()));

    QPushButton *buttonQuit = new QPushButton("Quit", &window);
    buttonQuit->setGeometry(10, 40, 80, 30);

    QObject::connect(buttonQuit, SIGNAL(clicked()), qApp, SLOT(quit()));

    return app.exec();


    #include "window.h"
    #include <QPushButton>
    #include <QApplication>
    #include <QToolTip>
    #include <QPoint>
    #include <QWidget>
    #include <QDebug>
    #include <QLabel>

    Window::Window(QWidget *parent) :
    // Set size of the window

    setFixedSize(100, 50);

    //Create and position the button
    m_button = new QPushButton("Click me", this);
    m_button->setGeometry(10, 10, 80, 30);

    QObject::connect(this, SIGNAL (clicked()), this, SLOT(checkText()));

    void Window::checkText(){

    QLabel *label1 = new QLabel();
    label1->setText("Hello World");

  • Lifetime Qt Champion

    Hi and welcome to the forums.

    You lie to it :)
    QObject::connect(buttonInfo,SIGNAL(clicked()), qApp, SLOT(checkText()));
    you say that qApp has the checkText function but it does not.

    it seems to be windows class that has it so
    QObject::connect(buttonInfo,SIGNAL(clicked()), &window, SLOT(checkText()));

    if that windows instance is the one that has

    However, that aside.
    why are you creating the buttons in main ?
    should they not be in mainwindow or similar?
    if they are not part of a form/window, you cannot really see them.

  • Thank you for your reply, but it still does not work

    I am not quite sure how can create a button in mainwindow and not in main

  • Lifetime Qt Champion


    Well you just open the mainwindows ui file and drag the buttons from left side to it.

    it seems you made your own Window class that is just a widget with no UI file ?

    Both ways can work but using an UI file make it super easy as you can then simply design it versus hand code it.

    You can make a new Widget/window with
    alt text

    and it will have an UI file and allow you just just drag the buttons to it

    alt text

  • I know, but i wanted to create the buttons with no UI file in order to learn the basics of hand coding a button

    I used the tip you gave me before, but I am still getting the same error code

  • @mrjj

    With your first message it finally worked!
    I really appreciate your help!

  • Lifetime Qt Champion

    Ok super.
    Well its a good idea to learn the basic by hand coding.
    Just as a note. When you use an UI file its just also code.
    if you look in the setupUI function you can see the c++ code generated from the UI files.
    That can be used to visually build something and then study the code.
    This is handy with say with a complex layout.
    Also you can mix UI and hand code. no issues.
    Just add stuff after the setupUI and it works as expected/normal.

Log in to reply