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. How to transffer QImage or QPixmap from one window to another using signals and slots

How to transffer QImage or QPixmap from one window to another using signals and slots

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 5 Posters 3.0k 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.
  • S Offline
    S Offline
    swansorter
    wrote on 3 Nov 2021, 07:16 last edited by
    #1

    Hi i want send Qimage or Qpixmap from one window to another ?

    J 1 Reply Last reply 3 Nov 2021, 07:17
    0
    • S swansorter
      3 Nov 2021, 07:16

      Hi i want send Qimage or Qpixmap from one window to another ?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 3 Nov 2021, 07:17 last edited by
      #2

      @swansorter What exactly is the problem?
      Create a signal with QImage* or QPixmap* parameter and also a slot with same parameter...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 3 Nov 2021, 08:00
      1
      • J jsulm
        3 Nov 2021, 07:17

        @swansorter What exactly is the problem?
        Create a signal with QImage* or QPixmap* parameter and also a slot with same parameter...

        S Offline
        S Offline
        swansorter
        wrote on 3 Nov 2021, 08:00 last edited by swansorter 11 Mar 2021, 08:01
        #3

        @jsulm Hi i tried

        I defined onGetImage on Mainwindow.h
        public slots:
        void onGetImage(const QImage &img);

        I defined sendImage on my_qlabel.h
        signals:
        void sendImage(const QImage &frame);

        my_qlabel *test_label=new my_qlabel();
        connect(test_label,&my_qlabel::sendImage,this,&MainWindow::onGetImage);

        but it is not displaying the image

        J J 2 Replies Last reply 3 Nov 2021, 08:03
        0
        • S swansorter
          3 Nov 2021, 08:00

          @jsulm Hi i tried

          I defined onGetImage on Mainwindow.h
          public slots:
          void onGetImage(const QImage &img);

          I defined sendImage on my_qlabel.h
          signals:
          void sendImage(const QImage &frame);

          my_qlabel *test_label=new my_qlabel();
          connect(test_label,&my_qlabel::sendImage,this,&MainWindow::onGetImage);

          but it is not displaying the image

          J Offline
          J Offline
          JonB
          wrote on 3 Nov 2021, 08:03 last edited by JonB 11 Mar 2021, 08:06
          #4

          @swansorter said in How to transffer QImage or QPixmap from one window to another using signals and slots:

          but it is not displaying the image

          What is "not displaying the image"? Your code, as shown, does not do anything about putting the received image into anything on Mainwindow in the slot!

          S 1 Reply Last reply 3 Nov 2021, 08:34
          0
          • J JonB
            3 Nov 2021, 08:03

            @swansorter said in How to transffer QImage or QPixmap from one window to another using signals and slots:

            but it is not displaying the image

            What is "not displaying the image"? Your code, as shown, does not do anything about putting the received image into anything on Mainwindow in the slot!

            S Offline
            S Offline
            swansorter
            wrote on 3 Nov 2021, 08:34 last edited by swansorter 11 Mar 2021, 08:38
            #5

            @JonB After receiving the image in the main window i am displaying the the image on qlable .there am not able to see the image.

            void MainWindow::onGetImage(const QImage dat)
            {

            ui->label_2->setPixmap(QPixmap::fromImage(dat)); //show "image"
            }

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 3 Nov 2021, 08:39 last edited by
              #6

              Hi,

              How do you create that image ?
              Is it valid ?
              Are you sure that your slot is called ?

              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 3 Nov 2021, 08:40
              1
              • S SGaist
                3 Nov 2021, 08:39

                Hi,

                How do you create that image ?
                Is it valid ?
                Are you sure that your slot is called ?

                S Offline
                S Offline
                swansorter
                wrote on 3 Nov 2021, 08:40 last edited by swansorter 11 Mar 2021, 08:41
                #7

                @SGaist Yea its not even going to slot function only y?

                S 1 Reply Last reply 3 Nov 2021, 08:43
                0
                • S swansorter
                  3 Nov 2021, 08:40

                  @SGaist Yea its not even going to slot function only y?

                  S Offline
                  S Offline
                  swansorter
                  wrote on 3 Nov 2021, 08:43 last edited by
                  #8

                  @swansorter I am receiving the rgb data over tcp client and then after framing the image i am sending it to mainwndow

                  J 1 Reply Last reply 3 Nov 2021, 08:45
                  0
                  • S swansorter
                    3 Nov 2021, 08:43

                    @swansorter I am receiving the rgb data over tcp client and then after framing the image i am sending it to mainwndow

                    J Offline
                    J Offline
                    JonB
                    wrote on 3 Nov 2021, 08:45 last edited by
                    #9

                    @swansorter
                    You show a connect() but no emit sendImage(...). If you are not getting to the slot, where are you emitting the signal?

                    S 1 Reply Last reply 3 Nov 2021, 08:49
                    0
                    • J JonB
                      3 Nov 2021, 08:45

                      @swansorter
                      You show a connect() but no emit sendImage(...). If you are not getting to the slot, where are you emitting the signal?

                      S Offline
                      S Offline
                      swansorter
                      wrote on 3 Nov 2021, 08:49 last edited by
                      #10

                      @JonB
                      QImage img(1024, 150, QImage::Format_RGB888);

                             int pixel=0;
                             for (int y =  150-1; y>= 0; y--)
                             {
                                for (int x = 0; x < 1024; x++)
                                {
                                     img.setPixel(x,y,qRgb(((data[pixel+2]) ),(data[pixel+1]), (data[pixel+0])));
                                     pixel+=3;
                                }
                      
                             } 
                            emit sendImage(img);
                      
                      J 1 Reply Last reply 3 Nov 2021, 08:51
                      0
                      • S swansorter
                        3 Nov 2021, 08:49

                        @JonB
                        QImage img(1024, 150, QImage::Format_RGB888);

                               int pixel=0;
                               for (int y =  150-1; y>= 0; y--)
                               {
                                  for (int x = 0; x < 1024; x++)
                                  {
                                       img.setPixel(x,y,qRgb(((data[pixel+2]) ),(data[pixel+1]), (data[pixel+0])));
                                       pixel+=3;
                                  }
                        
                               } 
                              emit sendImage(img);
                        
                        J Offline
                        J Offline
                        JonB
                        wrote on 3 Nov 2021, 08:51 last edited by
                        #11

                        @swansorter
                        Either you do not hit that code or you have not connected the correct signal instance to the correct slot instance, if you say the slot is not hit. Put a qDebug() << "Slot" as first statement in onGetImage() and see whether it gets printed or not.

                        S 1 Reply Last reply 3 Nov 2021, 08:52
                        0
                        • J JonB
                          3 Nov 2021, 08:51

                          @swansorter
                          Either you do not hit that code or you have not connected the correct signal instance to the correct slot instance, if you say the slot is not hit. Put a qDebug() << "Slot" as first statement in onGetImage() and see whether it gets printed or not.

                          S Offline
                          S Offline
                          swansorter
                          wrote on 3 Nov 2021, 08:52 last edited by
                          #12

                          @JonB it is not printing i tried

                          J 1 Reply Last reply 3 Nov 2021, 08:52
                          0
                          • S swansorter
                            3 Nov 2021, 08:52

                            @JonB it is not printing i tried

                            J Offline
                            J Offline
                            JonB
                            wrote on 3 Nov 2021, 08:52 last edited by JonB 11 Mar 2021, 08:53
                            #13

                            @swansorter
                            Then as I said

                            Either you do not hit that [emit] code or you have not connected the correct signal instance to the correct slot instance

                            S 1 Reply Last reply 3 Nov 2021, 08:57
                            0
                            • J JonB
                              3 Nov 2021, 08:52

                              @swansorter
                              Then as I said

                              Either you do not hit that [emit] code or you have not connected the correct signal instance to the correct slot instance

                              S Offline
                              S Offline
                              swansorter
                              wrote on 3 Nov 2021, 08:57 last edited by swansorter 11 Mar 2021, 08:58
                              #14

                              @JonB i tried qDebug() << "EMIT" near the emit signal. and it is executing

                              J 1 Reply Last reply 3 Nov 2021, 09:12
                              0
                              • S swansorter
                                3 Nov 2021, 08:57

                                @JonB i tried qDebug() << "EMIT" near the emit signal. and it is executing

                                J Offline
                                J Offline
                                JonB
                                wrote on 3 Nov 2021, 09:12 last edited by JonB 11 Mar 2021, 09:12
                                #15

                                @swansorter
                                Then

                                or you have not connected the correct signal instance to the correct slot instance

                                (or, for example, your signal or slot objects have gone out of scope or life-time. I don't know what else to say. You know that signals & slots work, so there is a problem in your code.

                                Produce a minimal example. To rule out a problem with transferring a const QImage & as the parameter, temporarily change signal & slot to transfer, say, a QString, and emit sendImage("Hello"); till you get that working....

                                S 1 Reply Last reply 3 Nov 2021, 09:43
                                0
                                • J JonB
                                  3 Nov 2021, 09:12

                                  @swansorter
                                  Then

                                  or you have not connected the correct signal instance to the correct slot instance

                                  (or, for example, your signal or slot objects have gone out of scope or life-time. I don't know what else to say. You know that signals & slots work, so there is a problem in your code.

                                  Produce a minimal example. To rule out a problem with transferring a const QImage & as the parameter, temporarily change signal & slot to transfer, say, a QString, and emit sendImage("Hello"); till you get that working....

                                  S Offline
                                  S Offline
                                  swansorter
                                  wrote on 3 Nov 2021, 09:43 last edited by swansorter 11 Mar 2021, 09:44
                                  #16

                                  @JonB i changed to Qstring and hello is not displaying. how to rectify this problem

                                  K J 2 Replies Last reply 3 Nov 2021, 09:51
                                  0
                                  • S swansorter
                                    3 Nov 2021, 08:00

                                    @jsulm Hi i tried

                                    I defined onGetImage on Mainwindow.h
                                    public slots:
                                    void onGetImage(const QImage &img);

                                    I defined sendImage on my_qlabel.h
                                    signals:
                                    void sendImage(const QImage &frame);

                                    my_qlabel *test_label=new my_qlabel();
                                    connect(test_label,&my_qlabel::sendImage,this,&MainWindow::onGetImage);

                                    but it is not displaying the image

                                    J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 3 Nov 2021, 09:48 last edited by
                                    #17

                                    @swansorter said in How to transffer QImage or QPixmap from one window to another using signals and slots:

                                    my_qlabel *test_label=new my_qlabel();
                                    connect(test_label,&my_qlabel::sendImage,this,&MainWindow::onGetImage);

                                    Is it possible that you're creating another test_label somewhere and emit the signal there?
                                    Without more information (code) we can't treally help.

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0
                                    • S swansorter
                                      3 Nov 2021, 09:43

                                      @JonB i changed to Qstring and hello is not displaying. how to rectify this problem

                                      K Offline
                                      K Offline
                                      KroMignon
                                      wrote on 3 Nov 2021, 09:51 last edited by
                                      #18

                                      @swansorter said in How to transffer QImage or QPixmap from one window to another using signals and slots:

                                      i changed to Qstring and hello is not displaying. how to rectify this problem

                                      Are you sure the connect() statement was successful?
                                      Are you sure to use the right class instance?
                                      Can you show my_qlabel class header?

                                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                      S 1 Reply Last reply 3 Nov 2021, 11:19
                                      0
                                      • S swansorter
                                        3 Nov 2021, 09:43

                                        @JonB i changed to Qstring and hello is not displaying. how to rectify this problem

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 3 Nov 2021, 10:09 last edited by
                                        #19

                                        @swansorter said in How to transffer QImage or QPixmap from one window to another using signals and slots:

                                        how to rectify this problem

                                        Like I said, produce a minimal example, paste the code, and we will tell you what you are doing wrong.....

                                        S 2 Replies Last reply 3 Nov 2021, 11:16
                                        0
                                        • J JonB
                                          3 Nov 2021, 10:09

                                          @swansorter said in How to transffer QImage or QPixmap from one window to another using signals and slots:

                                          how to rectify this problem

                                          Like I said, produce a minimal example, paste the code, and we will tell you what you are doing wrong.....

                                          S Offline
                                          S Offline
                                          swansorter
                                          wrote on 3 Nov 2021, 11:16 last edited by swansorter 11 Mar 2021, 11:35
                                          #20

                                          @JonB

                                          mainwindow.h file
                                          #ifndef MAINWINDOW_H
                                          #define MAINWINDOW_H
                                          
                                          #include <QMainWindow>
                                          #include<QRubberBand>
                                          #include<my_qlabel.h>
                                          namespace Ui {
                                          class MainWindow;
                                          }
                                          
                                          class MainWindow : public QMainWindow
                                          {
                                              Q_OBJECT
                                          
                                          public:
                                              explicit MainWindow(QWidget *parent = 0);
                                              ~MainWindow();
                                                 static QPoint origin;
                                                 static QPoint Move_test;
                                                 static QRect f_r;
                                           private slots:
                                              void onGetImage (QString data);
                                          
                                          
                                          
                                          private:
                                              Ui::MainWindow *ui;
                                              my_qlabel *obj;
                                              QPoint origin_x;
                                          
                                          };
                                          
                                          #endif // MAINWINDOW_H
                                          
                                          

                                          ``
                                          my qlable.h file`
                                          #ifndef MY_QLABEL_H
                                          #define MY_QLABEL_H

                                          #include <QWidget>
                                          #include <QLabel>
                                          #include <QEvent>
                                          #include <QMouseEvent>
                                          #include <QDebug>
                                          #include<QRubberBand>
                                          class my_qlabel : public QLabel
                                          {
                                          Q_OBJECT
                                          public:
                                          explicit my_qlabel(QWidget *parent = 0);
                                          void mouseMoveEvent(QMouseEvent *ev);
                                          void mousePressEvent(QMouseEvent *ev);
                                          void mouseReleaseEvent(QMouseEvent *ev);
                                          int x,y;
                                          signals:
                                          void onSendImage(QString data);

                                          public slots:
                                          private:

                                          QRubberBand *rubberBand=0;
                                          
                                          QPoint origin_x;
                                          

                                          };

                                          #endif // MY_QLABEL_H

                                          
                                          

                                          #include "mainwindow.h"
                                          #include "ui_mainwindow.h"
                                          QPoint MainWindow::origin;
                                          QPoint MainWindow::Move_test;
                                          QRect MainWindow::f_r;
                                          MainWindow::MainWindow(QWidget *parent) :
                                          QMainWindow(parent),
                                          ui(new Ui::MainWindow)
                                          {
                                          ui->setupUi(this);
                                          ui->label->setStyleSheet("QLabel{background: yellow;}");
                                          obj=new my_qlabel(this);
                                          connect(obj,SIGNAL(onSendimage(QString)),this,SLOT(onGetimage(QString)));
                                          }

                                          MainWindow::~MainWindow()
                                          {
                                          delete ui;
                                          }

                                          void MainWindow::onGetimage (QString data)
                                          {
                                          QPixmap image=data ;
                                          ui->label_2->setPixmap(image);
                                          }

                                          
                                          

                                          #include "my_qlabel.h"
                                          #include<mainwindow.h>
                                          my_qlabel::my_qlabel(QWidget *parent) :
                                          QLabel(parent)
                                          {
                                          emit Mouse_Left("image");
                                          }

                                          void my_qlabel::mouseMoveEvent(QMouseEvent *ev)
                                          {
                                          this->x = ev->x();
                                          this->y = ev->y();
                                          rubberBand->setGeometry(QRect(origin_x,ev->pos()).normalized());

                                          }

                                          void my_qlabel::mousePressEvent(QMouseEvent *ev)
                                          {

                                          origin_x=ev->pos();
                                          if(!rubberBand)
                                              rubberBand=new QRubberBand(QRubberBand::Rectangle,this);
                                          rubberBand->setGeometry(QRect((origin_x),QSize()));
                                          rubberBand->show();
                                          

                                          }

                                          void my_qlabel::mouseReleaseEvent(QMouseEvent *ev)
                                          {

                                              rubberBand->hide();
                                          
                                              MainWindow::f_r=rubberBand->geometry();
                                              qDebug()<<"f_r"<<MainWindow::f_r;
                                              QPixmap  image(rubberBand->geometry().width(),rubberBand->geometry().height());
                                              image = grab(rubberBand->geometry()); //copy the selected part
                                          
                                              emit onSendimage("image");
                                          

                                          }

                                          J 1 Reply Last reply 3 Nov 2021, 11:29
                                          0

                                          7/29

                                          3 Nov 2021, 08:40

                                          topic:navigator.unread, 22
                                          • Login

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