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. [SOLVED] application segfaults when assigning pixmap for Label
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] application segfaults when assigning pixmap for Label

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 3.1k Views 1 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.
  • D Offline
    D Offline
    dqqw
    wrote on last edited by
    #1

    i am writing a qt4 gui application which has the following:
    -a main window with a widget which will hold:
    -an ogre instance (that is not important now, it is left empty)
    -a dockwidget with 2 buttons: one will cause the rendering of an image and show a dialog window, the other button just shows/hides the dialog window
    -a dialog window to show the image (i have read somewhere that i should just put a label and use setpixmap to assign a pixmat to it)

    here are my sources: http://pastebin.com/HXkT3Jut
    here are the ui files: http://pastebin.com/0TKKDziv

    the segfault happens at this line:
    raytracerRenderDialog->renderedImageContainer->setPixmap(QPixmap::fromImage(renderedImage));

    a few notes:
    -i know that the way i implemented on_actionShow_render_triggered and on_actionRender_triggered is not the correct way, it is just temporary to see how it works
    -the application flow is like this: press render button -> generate raw image pixels -> show generated image in dialog

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Can you check that the QImage is valid ? e.g. do you have Tux.png in the same folder as your application executable ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dqqw
        wrote on last edited by
        #3

        i'm pretty sure that it loads the image, because when i run it in debug mode, in the locals it displays the resolution of the image

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You should confirm it with a test like

          @
          if (!renderedImage.isNull())
          qDebug() << "invalid image";
          @

          On a related note, you can create a QPixmap from a file, that would save you the conversion there

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dqqw
            wrote on last edited by
            #5

            modified the code as follows:
            @void RaytracerMainWindow::on_actionRender_triggered()
            {
            QImage renderedImage;
            renderedImage.load("Tux.png");
            if(!renderedImage.isNull()){
            qDebug() << "invalid image";
            }else{
            qDebug() << "image loaded";
            }

            raytracerRenderDialog->renderedImageContainer->show();
            
            //raytracerRenderDialog->renderedImageContainer->setPixmap(QPixmap::fromImage(renderedImage));
            
            ui->actionShow_render->setChecked(true);
            

            }@

            it outputs "image loaded "

            and on a sidenote raytracerRenderDialog->renderedImageContainer->show(); crashes the application

            could you please take a look at the RaytracerRenderDialog class?
            i think the problem comes from there.

            see i created a mainwindow (RaytracerMainWindow) and a dialog (RenderDialog), the creator generated the correct headers and classes for them.
            but when i tried to instanciate a RaytracerRenderDialog inside RaytracerMainWindow, the compiler threw all kinds of redefinition error and such.
            so i read somewhere i must derive a class to be able to instantiate it.
            i think something is messed up in the constructor of RaytracerRenderDialog.

            in the past few yeard i coded mostly strictly in C, so it is hard for me to get back to the C++ mentality, let aloge getting used to QT's own mechanisms.

            thanks

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You are doing the test wrong, if isNull() is true you have an invalid image

              Are you sure renderedImageContainer is initialized correctly ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dqqw
                wrote on last edited by
                #7

                yeah, that was a copy-paste problem, and it did not have the tux.png next to it because i moved the project folder and the build folder changed too...
                yeah and i copy pasted your code without actually checking... :D

                i THINK i initialize it correctly:
                @RaytracerMainWindow::RaytracerMainWindow(QWidget *parent):
                QMainWindow(parent),
                ui(new Ui::RaytracerMainWindow)
                {
                ui->setupUi(this);
                raytracerRenderDialog= new RaytracerRenderDialog(parent);
                }@

                which calls this:
                @RaytracerRenderDialog::RaytracerRenderDialog(QWidget *parent):
                QDialog(parent),
                renderDialog(new Ui::RenderDialog)
                {
                renderDialog->setupUi(this);
                }@

                somewhere in the middle i realized that qt widget classes keep a reference to themselves as a pointer of ther class, but some things are not very clean to me

                if it would help i could upload an archive of the project itself

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Where is renderedImageContainer declared ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dqqw
                    wrote on last edited by
                    #9

                    since it was added with the desginer:

                    <widget class="QLabel" name="renderedImageContainer">
                    <property name="styleSheet">
                    <string notr="true">background-color: rgb(128, 128, 128);</string>
                    </property>
                    <property name="text">
                    <string/>
                    </property>
                    </widget>

                    so it is declared in the intermediary ui_renderdialog.h, which is generated.

                    i assumed it should be initialized since i call the setuUi method for RenderDialog from RaytracerRenderDialog

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Did you run your application through the debugger ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dqqw
                        wrote on last edited by
                        #11

                        solved it.

                        added
                        @void RenderDialog::setRenderedImage(QPixmap pixmap)
                        {
                        ui->renderedImageContainer->setPixmap(pixmap);
                        }@

                        to RenderDialog

                        and called it like this from raytreacermainwindow:
                        @void RaytracerMainWindow::on_actionRender_triggered()
                        {
                        QImage renderedImage;
                        renderedImage.load("Tux.png");
                        if(renderedImage.isNull()){
                        qDebug() << "invalid image";
                        }else{
                        qDebug() << "image loaded";
                        }

                        RenderDialog *renderDialog= new RenderDialog();
                        
                        renderDialog->setRenderedImage(QPixmap::fromImage(renderedImage));
                        
                        renderDialog->show();
                        

                        }@

                        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