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. class derivated from QImage as parameter of signal
Forum Updated to NodeBB v4.3 + New Features

class derivated from QImage as parameter of signal

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 549 Views 2 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.
  • S Offline
    S Offline
    stephane78 0
    wrote on last edited by
    #1

    Hi,
    How to send an Image * (derivated from QImage) as parameter of a signal ?

    I have put:

    Q_DECLARE_METATYPE(Image)
    Q_DECLARE_OPAQUE_POINTER(Image *)

    1 Reply Last reply
    0
    • mrjjM mrjj

      Hi
      Sending a pointer requires nothing extra as its a value and can be copied and queued by default.
      So you can just do it.

      signals:
          void mysignal(Image *);
      public slots:
          void myslot(Image *);
      
          connect(this, &MainWindow::mysignal, this, &MainWindow::myslot );
          auto test = new Image;
          emit mysignal(test);
      

      and it will work.

      S Offline
      S Offline
      stephane78 0
      wrote on last edited by
      #5

      @mrjj ok my problem is solved I have replaced void mysignal(Image ,QString &) by void mysignal(Image,QString *) and now it works , thanks.

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

        Hi
        Sending a pointer requires nothing extra as its a value and can be copied and queued by default.
        So you can just do it.

        signals:
            void mysignal(Image *);
        public slots:
            void myslot(Image *);
        
            connect(this, &MainWindow::mysignal, this, &MainWindow::myslot );
            auto test = new Image;
            emit mysignal(test);
        

        and it will work.

        S 2 Replies Last reply
        1
        • mrjjM mrjj

          Hi
          Sending a pointer requires nothing extra as its a value and can be copied and queued by default.
          So you can just do it.

          signals:
              void mysignal(Image *);
          public slots:
              void myslot(Image *);
          
              connect(this, &MainWindow::mysignal, this, &MainWindow::myslot );
              auto test = new Image;
              emit mysignal(test);
          

          and it will work.

          S Offline
          S Offline
          stephane78 0
          wrote on last edited by
          #3

          @mrjj thank you but is it possible to send as parameter of a signal a QString & ?
          because my signal is mysignal(Image*,QString &) and I don't receive the signal
          it is emitted from the end of the function run from a class derivated from QThread to the mainwindow.

          mrjjM 1 Reply Last reply
          0
          • S stephane78 0

            @mrjj thank you but is it possible to send as parameter of a signal a QString & ?
            because my signal is mysignal(Image*,QString &) and I don't receive the signal
            it is emitted from the end of the function run from a class derivated from QThread to the mainwindow.

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

            @stephane78-0

            Hi
            QString already works in any combination so that should not be it.
            mysignal(Image*,QString &) should also just work. ( slot has to match of cause )

            So i think it something else :)

            1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              Sending a pointer requires nothing extra as its a value and can be copied and queued by default.
              So you can just do it.

              signals:
                  void mysignal(Image *);
              public slots:
                  void myslot(Image *);
              
                  connect(this, &MainWindow::mysignal, this, &MainWindow::myslot );
                  auto test = new Image;
                  emit mysignal(test);
              

              and it will work.

              S Offline
              S Offline
              stephane78 0
              wrote on last edited by
              #5

              @mrjj ok my problem is solved I have replaced void mysignal(Image ,QString &) by void mysignal(Image,QString *) and now it works , thanks.

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

                Hi,

                Why are you sending a pointer to a QString ?

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

                S 1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  Why are you sending a pointer to a QString ?

                  S Offline
                  S Offline
                  stephane78 0
                  wrote on last edited by
                  #7

                  @SGaist I send the pointer on the resulting image and the pointer on the filename of the original image because in my slot I compute the filename of the resulting image and I display this image.But with the pointer on QString as parameter in the signal it works

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

                    Then you should rather use a const reference. But since you embed that file path in your class, why not use that ?

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

                    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