Results 1 to 2 of 2

Thread: Passing additional variables to signal slot.

  1. #1
    Join Date
    Dec 2015
    Location
    Poland
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Passing additional variables to signal slot.

    Hello.

    I extended Qlabel class with mousePressEvent to create my_qlabel:

    my_qlabel.cpp
    Qt Code:
    1. #include "my_qlabel.h"
    2. #include <QMouseEvent>
    3. #include <QDebug>
    4.  
    5. my_qlabel::my_qlabel(QWidget* parent) : QLabel(parent)
    6. {
    7.  
    8. }
    9.  
    10. void my_qlabel::mousePressEvent(QMouseEvent *event)
    11. {
    12. {
    13. if(event->button() == Qt::LeftButton)
    14. {
    15. int xwsp=event->x();
    16. int ywsp=event->y();
    17. emit leftClickAction(xwsp,ywsp);
    18. }
    19. else if(event->button() == Qt::RightButton)
    20. emit rightClickAction();
    21. }
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. connect(ui->label, SIGNAL(leftClickAction(int,int)), this, SLOT(leftclick(int,int)));
    7. connect(ui->label, SIGNAL(rightClickAction()), this, SLOT(rightclick()));
    8. QPixmap pix("filelocation");
    9. QPixmap pixr = pix.scaledToHeight(600,Qt::SmoothTransformation);
    10. QPixmap * wsk_pixr;
    11. QPixmap * wsk_pix;
    12. wsk_pixr = & pixr;
    13. wsk_pix= & pix;
    14. setrs(wsk_pixr);// sets resized pix on myqlabel.
    15. }
    To copy to clipboard, switch view to plain text mode 

    Everything is working fine, but the question is: how can i pass "pix" or pointer to "pix"(Images are supposed to be around 10 mb each , so I assume passing pointer is much more time efficient than passing whole image.) created on program startup to "leftclick" or "rightclick" functions?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Passing additional variables to signal slot.

    QPixmap uses a pointer internally, so you can just copy its instances without much overhead.

    Both your functions are methods of MainWindow so you don't need to "pass" anything to them, just store the two pixmaps as members of MainWindow.

    Cheers,
    _

Similar Threads

  1. Passing additional arguments to a slot in pyqt4
    By pazgs in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2015, 09:51
  2. Replies: 1
    Last Post: 14th August 2014, 17:08
  3. Replies: 9
    Last Post: 27th March 2014, 09:45
  4. Passing data via signal/slot
    By gib in forum Qt Programming
    Replies: 4
    Last Post: 1st November 2010, 05:49
  5. Passing a pointer in Signal/Slot Connection
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 6th November 2007, 19:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.