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. No such slot ?
Forum Updated to NodeBB v4.3 + New Features

No such slot ?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k 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.
  • P Offline
    P Offline
    Project try
    wrote on last edited by
    #1

    Hey guys , sorry for asking lots of questions first :(

    second , I just finished my midterms " finally " :D , and I wanted to make a little calculator " I'm new so please don't get mad at me :D "

    so first I used a class that I used before to to convert to int " the line edit string " , so I added a button and a new line edit which is read only , and I wanted it to display x+y when the user clicks " compute " , the problem is it says no such slot for get_sum() and when I press compute after putting two numbers it doesn't show the answer.

    here's the header:

    @
    #ifndef CHECKCLASS_H
    #define CHECKCLASS_H
    #include<QLabel>
    #include<QHBoxLayout>
    #include<QLineEdit>
    #include<QIntValidator>
    #include<QWidget>
    #include<QPushButton>
    class checkclass : public QWidget
    {
    Q_OBJECT
    public:
    checkclass(QWidget *parent=0);

    private slots:

    void convert();
        void convert1();
        void get_sum();
    private:
        QPushButton *ReturnV;
        QLineEdit *edit;
        QLineEdit *edit1;
        QLineEdit *E;
    QIntValidator *Valid;
        QHBoxLayout *left;
    
        QHBoxLayout *Main;
    
        int x;
        int y;
    

    };

    #endif // CHECKCLASS_H
    @

    here's the imp:

    @
    #include "checkclass.h"

    checkclass::checkclass(QWidget *parent):
    QWidget(){
    Valid=new QIntValidator;
    edit = new QLineEdit;
    edit1=new QLineEdit;
    E=new QLineEdit;
    ReturnV=new QPushButton;
    ReturnV->setText("Compute");
    E->setReadOnly(true);

         left= new QHBoxLayout;
         Main=new QHBoxLayout;
            edit->setMaximumWidth(20);
            edit->setFixedWidth(20);
            edit->setValidator(Valid);
            edit1->setMaximumWidth(20);
            edit1->setFixedWidth(20);
            edit1->setValidator(Valid);
    
            QObject:: connect(edit,SIGNAL(editingFinished()),this,SLOT(convert()));
                   QObject:: connect(edit1,SIGNAL(editingFinished()),this,SLOT(convert1()));
                   QObject::connect(ReturnV,SIGNAL(clicked()),E,SLOT(get_sum()));
            left->addWidget(edit);
    
            left->addWidget(edit1);
            left->addWidget(E);
            left->addWidget(ReturnV);
            Main->addLayout(left);
    
    
            setLayout(Main);
    

    }

    void checkclass::convert(){
    QString numbertext=edit->text();
    x=numbertext.toInt();

    }
    void checkclass::convert1(){
    QString numbertext=edit1->text();
    y=numbertext.toInt();

    }
    void checkclass::get_sum(){
    int z=x+y;
    QString textN= QString::number(z);
    E->setText(textN);

    }
    @

    Thanks in advance.

    1 Reply Last reply
    0
    • hskoglundH Online
      hskoglundH Online
      hskoglund
      wrote on last edited by
      #2

      Hi, this line:
      QObject::connect(ReturnV,SIGNAL(clicked()),E,SLOT(get_sum()));
      try change E to this:
      QObject::connect(ReturnV,SIGNAL(clicked()),this,SLOT(get_sum()));

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Project try
        wrote on last edited by
        #3

        Ah man thanks it worked , but could you explain why my way didn't work ? please :(

        1 Reply Last reply
        0
        • hskoglundH Online
          hskoglundH Online
          hskoglund
          wrote on last edited by
          #4

          Well, it could, but then you have to check, if the E class also has a
          slot: void get_sum() declared?

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Project try
            wrote on last edited by
            #5

            Ah , thank you ^^

            1 Reply Last reply
            0

            • Login

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