Results 1 to 2 of 2

Thread: qlabel can't use setPixmap() function

  1. #1
    Join Date
    Oct 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default qlabel can't use setPixmap() function

    I build a widget has a qlabel, below is its constructor
    Qt Code:
    1. #ifndef VIEWER_H
    2. #define VIEWER_H
    3.  
    4. #include <iostream>
    5.  
    6. #include <QWidget>
    7. #include <QPixmap>
    8. #include <QLabel>
    9. #include <QImage>
    10. #include <QVBoxLayout>
    11.  
    12.  
    13. using namespace std;
    14.  
    15. class Viewer : public QWidget
    16. {
    17. Q_OBJECT
    18.  
    19. public:
    20. Viewer(QWidget *parent=0);
    21. public slots:
    22. void setIplImage();
    23.  
    24.  
    25. private:
    26.  
    27. QVBoxLayout *mainLayout;
    28. QLabel *movieLabel;
    29.  
    30.  
    31. };
    32.  
    33. #endif
    34.  
    35. Viewer::Viewer(QWidget* parent)
    36. : QWidget(parent)
    37. {
    38. movieLabel = new QLabel(tr("No movie loaded"));
    39. movieLabel->setAlignment(Qt::AlignCenter);
    40. movieLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    41. movieLabel->setBackgroundRole(QPalette::Dark);
    42. movieLabel->setAutoFillBackground(true);
    43. movieLabel->setScaledContents(true);
    44.  
    45.  
    46.  
    47. mainLayout = new QVBoxLayout;
    48. mainLayout->addWidget(movieLabel);
    49. setLayout(mainLayout);
    50.  
    51. }
    52.  
    53.  
    54. void
    55. Viewer::setIplImage()
    56. {
    57.  
    58. QImage image("test.jpg");
    59. //image.save("test2.jpg"); //it works
    60.  
    61. movieLabel->setPixmap(QPixmap::fromImage(image)); //compile success but runtime error with access violation.
    62.  
    63. }
    To copy to clipboard, switch view to plain text mode 

    and if i use it in constructor, the setPixmap() can run.
    Thanks for any comments

  2. #2
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qlabel can't use setPixmap() function

    Are you by any chance calling setIplImage(), or connecting to it using Qt::DirectConnection, from a thread other than the GUI thread?

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 15:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 08:19
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 13:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 18:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 13:52

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.