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. The program freezes when an instance of a class is created
Qt 6.11 is out! See what's new in the release blog

The program freezes when an instance of a class is created

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 9 Posters 7.5k Views 4 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.
  • L_RaizL Offline
    L_RaizL Offline
    L_Raiz
    wrote on last edited by
    #3

    I'd try to pass imageToEnlarge argument by reference instead of value. Maybe something bad is going on when copying it during the call.

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #4

      What does the ImageDisplay constructor look like?

      G 1 Reply Last reply
      1
      • Paul ColbyP Paul Colby

        What does the ImageDisplay constructor look like?

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #5

        @Paul-Colby

        #ifndef IMAGEDISPLAY_H
        #define IMAGEDISPLAY_H
        
        #include <mainwindow.h>
        #include <additem.h>
        #include <review.h>
        #include <QDialog>
        
        namespace Ui {
        class ImageDisplay;
        }
        
        class ImageDisplay : public QDialog
        {
            Q_OBJECT
        
        public:
            explicit ImageDisplay(QWidget *parent = 0);
            ~ImageDisplay();
            void viewImage(QPixmap imageToEnlarge );
        
        private:
            Ui::ImageDisplay *ui;
        };
        
        #endif // IMAGEDISPLAY_H
        
        
        1 Reply Last reply
        0
        • G Offline
          G Offline
          gabor53
          wrote on last edited by
          #6

          Now it also sends a SIGSEGV error.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gabor53
            wrote on last edited by
            #7

            It also displays the following messages:
            can't find linker symbol for virtual table for QPixmap' value found _q_ObjectMutexPool' instead
            can't find linker symbol for virtual table for QPixmap' value found _q_ObjectMutexPool' instead
            Column 2 was chosen.
            can't find linker symbol for virtual table for QPixmap' value found _q_ObjectMutexPool' instead
            can't find linker symbol for virtual table for QPixmap' value found _q_ObjectMutexPool' instead

            jsulmJ 1 Reply Last reply
            0
            • G gabor53

              It also displays the following messages:
              can't find linker symbol for virtual table for QPixmap' value found _q_ObjectMutexPool' instead
              can't find linker symbol for virtual table for QPixmap' value found _q_ObjectMutexPool' instead
              Column 2 was chosen.
              can't find linker symbol for virtual table for QPixmap' value found _q_ObjectMutexPool' instead
              can't find linker symbol for virtual table for QPixmap' value found _q_ObjectMutexPool' instead

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @gabor53 Can you please show the content of the ImageDisplay constructor, not just its declaration?

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

              G 1 Reply Last reply
              1
              • jsulmJ jsulm

                @gabor53 Can you please show the content of the ImageDisplay constructor, not just its declaration?

                G Offline
                G Offline
                gabor53
                wrote on last edited by
                #9

                @jsulm
                Here it is:

                #include "imagedisplay.h"
                #include "ui_imagedisplay.h"
                
                ImageDisplay::ImageDisplay(QWidget *parent) :
                    QDialog(parent),
                    ui(new Ui::ImageDisplay)
                {
                    ui->setupUi(this);
                
                    ImageDisplay(imageToEnlarge);
                }
                
                ImageDisplay::~ImageDisplay()
                {
                    delete ui;
                }
                
                void ImageDisplay::viewImage(QPixmap imageToEnlarge)
                {
                    int w = ui->ImageLabel->width ();
                    int h = ui->ImageLabel->height ();
                    ui->ImageLabel->setPixmap (imageToEnlarge.scaled(w,h,Qt::KeepAspectRatio));
                }
                
                

                Thank you.

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

                  ImageDisplay::ImageDisplay(QWidget *parent) :
                  QDialog(parent),
                  ui(new Ui::ImageDisplay)
                  {
                  ui->setupUi(this);
                  ImageDisplay(imageToEnlarge); <<<<<< Call ctor again !! ?!

                  should that not be viewImage(QPixmap imageToEnlarge) ?

                  kshegunovK 1 Reply Last reply
                  2
                  • G gabor53

                    @jsulm
                    Here it is:

                    #include "imagedisplay.h"
                    #include "ui_imagedisplay.h"
                    
                    ImageDisplay::ImageDisplay(QWidget *parent) :
                        QDialog(parent),
                        ui(new Ui::ImageDisplay)
                    {
                        ui->setupUi(this);
                    
                        ImageDisplay(imageToEnlarge);
                    }
                    
                    ImageDisplay::~ImageDisplay()
                    {
                        delete ui;
                    }
                    
                    void ImageDisplay::viewImage(QPixmap imageToEnlarge)
                    {
                        int w = ui->ImageLabel->width ();
                        int h = ui->ImageLabel->height ();
                        ui->ImageLabel->setPixmap (imageToEnlarge.scaled(w,h,Qt::KeepAspectRatio));
                    }
                    
                    

                    Thank you.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @gabor53 To add to @mrjj: what is imageToEnlarge in

                    ImageDisplay::ImageDisplay(QWidget *parent) :
                        QDialog(parent),
                        ui(new Ui::ImageDisplay)
                    {
                        ui->setupUi(this);
                    
                        ImageDisplay(imageToEnlarge);
                    }
                    

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

                    1 Reply Last reply
                    0
                    • mrjjM mrjj

                      ImageDisplay::ImageDisplay(QWidget *parent) :
                      QDialog(parent),
                      ui(new Ui::ImageDisplay)
                      {
                      ui->setupUi(this);
                      ImageDisplay(imageToEnlarge); <<<<<< Call ctor again !! ?!

                      should that not be viewImage(QPixmap imageToEnlarge) ?

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #12

                      How does this even compile? You're not allowed to call constructors explicitly ... probably it creates a temporary ...

                      Read and abide by the Qt Code of Conduct

                      VRoninV 1 Reply Last reply
                      1
                      • kshegunovK kshegunov

                        How does this even compile? You're not allowed to call constructors explicitly ... probably it creates a temporary ...

                        VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by
                        #13

                        @kshegunov said in The program freezes when an instance of a class is created:

                        How does this even compile?

                        another problem is that in the constructor imageToEnlarge should be an undefined symbol. if it is defined in that constructor then there is a naming conflict in viewImage. this should 100% not compile

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        1 Reply Last reply
                        1
                        • G Offline
                          G Offline
                          gabor53
                          wrote on last edited by
                          #14
                          ImageDisplay::ImageDisplay(QWidget *parent) :
                              QDialog(parent),
                              ui(new Ui::ImageDisplay)
                          {
                              ui->setupUi(this);
                          
                              ImageDisplay(imageToEnlarge);
                          }
                          
                          ImageDisplay::~ImageDisplay()
                          

                          I deleted ImageDisplay(imageToEnlarge). As a result it doesn't freeze but doesn't display the image I clicked on either.

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            josephdp
                            wrote on last edited by
                            #15

                            As what others suggested, the content of the form constructor is wrong.
                            Your widgets are already taken care of by setupUI().
                            Thus, the logic of displaying the image should just be in viewImage ().

                            QPixmap imageToEnlarge = index.data(Qt::DecorationRole).value<QPixmap>();
                            

                            where is the data in this?

                            here's a brief example using QT's QImage.

                            QPixmap scaledPixmap = QPixmap::fromImage (image).scaled (
                                QSize (w, h),
                                Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                            
                            ui->ImageLabel->setPixmap (scaledPixmap);
                            
                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              gabor53
                              wrote on last edited by
                              #16

                              The following seems to work:

                              void MainWindow::on_tableView_clicked(const QModelIndex &index)
                              {
                                  int row = index.row ();
                                  int column = index.column ();
                                  qDebug() << "Index: " << "(" << row <<"," << column << ")";
                              
                                  if(column == 2)
                                      {
                                          qDebug() << "Column 2 was chosen.";
                              
                                          QPixmap imageToEnlarge = index.data(Qt::DecorationRole).value<QPixmap>();
                              
                                          int w = ui->label_Temp->width();
                                          int h = ui->label_Temp->height ();
                                          ui->label_Temp->setPixmap (imageToEnlarge.scaled(w,h,Qt::KeepAspectRatio));
                                          ImageDisplay *mImageDisplay = new ImageDisplay;
                                          mImageDisplay->viewImage(imageToEnlarge);
                                          mImageDisplay->exec ();
                              
                                      }
                              }
                              

                              Thank you for your help.

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

                                super
                                You should get rid of new or add a delete

                                ImageDisplay *mImageDisplay = new ImageDisplay;
                                mImageDisplay->viewImage(imageToEnlarge);
                                mImageDisplay->exec ();
                                delete ImageDisplay; /// clean up
                                

                                or simply dont use new as you use exec()

                                ImageDisplay mImageDisplay;
                                mImageDisplay.viewImage(imageToEnlarge);
                                mImageDisplay.exec ();
                                
                                1 Reply Last reply
                                2
                                • G Offline
                                  G Offline
                                  gabor53
                                  wrote on last edited by
                                  #18

                                  Thank you!!

                                  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