Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QObject::connect: No such slot QApplication::checkText()
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 940 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chaki
    wrote on last edited by
    #1

    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:

    window.h

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

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

    signals:
    void QApplication();
    private slots:

    void checkText();

    private:

    QPushButton *m_button;
    

    };

    #endif // WINDOW_H

    ###########
    main.cpp

    #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.show();
    window.showMaximized();
    window.setFixedSize(100, 80);

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

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

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

    return app.exec();
    }

    #############
    window.cpp

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

    Window::Window(QWidget *parent) :
    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);
    m_button->setCheckable(true);

      m_button->show();
    QObject::connect(this, SIGNAL (clicked()), this, SLOT(checkText()));
    

    }
    void Window::checkText(){

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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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
      Window::checkText()

      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.

      1 Reply Last reply
      3
      • C Offline
        C Offline
        Chaki
        wrote on last edited by
        #3

        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

        mrjjM 1 Reply Last reply
        0
        • C Chaki

          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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Chaki

          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

          1 Reply Last reply
          2
          • C Offline
            C Offline
            Chaki
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Chaki
              wrote on last edited by
              #6

              @mrjj

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

              1 Reply Last reply
              1
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi
                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.

                1 Reply Last reply
                2

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved