Results 1 to 4 of 4

Thread: I imitated Image Viewer example but...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default I imitated Image Viewer example but...

    I exactly copied all the stuff from the Image Viewer example of Qt, except for the constructor. I modified it the constructor so it would auto load an image coming from another mainwindow that calls

    Qt Code:
    1. ImageViewer imageViewer(&image);
    To copy to clipboard, switch view to plain text mode 


    Now I am having trouble with the class because it closes/quits... and I am sure that that class's method show() ( opens for x milliseconds then closes).

    I've read this
    http://www.qtcentre.org/forum/f-qt-p...t=QApplication
    and it says two QApplication can't run at the same time. So how am I going to let the ImageViewer window stay (not instantly quit on show()). ? Because as of now I can't manually close it.. it closes on itself?

    Here goes the modified constructor of ImageViewer.

    Qt Code:
    1. ImageViewer::ImageViewer(const QImage *image) {
    2. imageLabel = new QLabel;
    3. imageLabel->setBackgroundRole(QPalette::Base);
    4. imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    5. imageLabel->setScaledContents(true);
    6.  
    7. scrollArea = new QScrollArea;
    8. scrollArea->setBackgroundRole(QPalette::Dark);
    9. scrollArea->setWidget(imageLabel);
    10. setCentralWidget(scrollArea);
    11.  
    12. createActions();
    13. createMenus();
    14.  
    15. setWindowTitle(tr("Image Viewer"));
    16. resize(500, 400);
    17.  
    18. // this is where the opening of the passed const image starts
    19.  
    20. if (image->isNull() || image == 0) {
    21. QMessageBox::information(this, tr("Image Viewer"),
    22. tr("Cannot load the image."));
    23. return;
    24. }
    25.  
    26. QPixmap pixmap = QPixmap::fromImage(*image);
    27.  
    28. imageLabel->setPixmap(pixmap);
    29. scaleFactor = 1.0;
    30.  
    31. printAct->setEnabled(true);
    32. fitToWindowAct->setEnabled(true);
    33. updateActions();
    34.  
    35. if (!fitToWindowAct->isChecked())
    36. imageLabel->adjustSize();
    37.  
    38. // suddenly closes ! ! !
    39. show();
    40. }
    To copy to clipboard, switch view to plain text mode 

    I've also read http://www.qtcentre.org/forum/f-qt-p...ght=maptoscene so. how do I NOT destroy the ImageViewer after calling its constructor?
    Last edited by sincnarf; 14th October 2007 at 15:57. Reason: confusing
    Image Analysis Development Framework Using Qt (IADFUQ)

Similar Threads

  1. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  2. Requirement for versatile image viewer
    By deekayt in forum General Discussion
    Replies: 1
    Last Post: 27th October 2006, 14:28
  3. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  4. Image Viewer
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 14th March 2006, 13:29
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19:01

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.