Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. connect the two class in signal ,slot and emit?

connect the two class in signal ,slot and emit?

Scheduled Pinned Locked Moved Solved Game Development
9 Posts 4 Posters 1.5k Views
  • 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.
  • A Offline
    A Offline
    amarism
    wrote on last edited by amarism
    #1

    I have to class file mainwindow and updater. Now i want to sent the data from updater to mainwindow.

    updater.h
     signals:
           void Ok(int x);
    
    
    updater.cpp
       void fun(){
              x = 10;
              emit Ok(x);
    }
    

    class form;
    mainwindow.h

    private slots:
         void receive(int x);
    
    #include "updater.h"
    mainwindow.cpp
    
    mainwindow::mainwindow(){
     updater*data = new updater(this);
    connect(data , &updater::Ok, this, &MainWindow::receiveOk);
    }
    
    void receiveOk(int x){
         cout << x;
    }
    

    I have done all these thing but still emit Signal not reflected inside the mainwindow.cpp file?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      What is the question?

      (Z(:^

      A 1 Reply Last reply
      0
      • sierdzioS sierdzio

        What is the question?

        A Offline
        A Offline
        amarism
        wrote on last edited by amarism
        #3

        @sierdzio try to send data from form.cpp file and access the same data inside mainwindow.cpp . when i try to send data from form.cpp file emit not emit the signal to mainwindow.cpp.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          OK, but instead of showing us code of your "form" class, you posted "updater" class.

          Also, in connect statement, you connect to "receiveOk" slot, but you pasted code for "receive" slot instead.

          Provide all the data and I'll try to help you. Right now I have no means of doing so.

          (Z(:^

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            @amarism said in connect the two class in signal ,slot and emit?:

            update.cpp
            void fun(){
            x = 10;
            emit Ok(int x);
            }

            The emit statement is wrong, it should be: emit Ok(x);

            @amarism said in connect the two class in signal ,slot and emit?:

            mainwindow.cpp
            connect(data , &Form::ok, this, &MainWindow::receiveOk);

            This won't compile as the name of the signal is wrong. It's Ok not ok

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply
            2
            • SGaistS SGaist

              Hi,

              @amarism said in connect the two class in signal ,slot and emit?:

              update.cpp
              void fun(){
              x = 10;
              emit Ok(int x);
              }

              The emit statement is wrong, it should be: emit Ok(x);

              @amarism said in connect the two class in signal ,slot and emit?:

              mainwindow.cpp
              connect(data , &Form::ok, this, &MainWindow::receiveOk);

              This won't compile as the name of the signal is wrong. It's Ok not ok

              A Offline
              A Offline
              amarism
              wrote on last edited by
              #6

              @SGaist I have correct all the thing but still emit not reflected into mainwindow.cpp

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Use qDebug in place of cout to see if you have a better result.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                A 1 Reply Last reply
                0
                • mranger90M Offline
                  mranger90M Offline
                  mranger90
                  wrote on last edited by
                  #8

                  @amarism said in connect the two class in signal ,slot and emit?:

                  void receiveOk(int x){
                  cout << x;
                  }

                  Shouldn't this be:

                  void mianwindow::receiveOk(int x){
                       cout << x;
                  }
                  
                  1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Use qDebug in place of cout to see if you have a better result.

                    A Offline
                    A Offline
                    amarism
                    wrote on last edited by
                    #9

                    @SGaist yup now i solve the issue 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