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]The program has unexpectedly finished.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]The program has unexpectedly finished.

Scheduled Pinned Locked Moved General and Desktop
image
6 Posts 4 Posters 2.6k Views 3 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.
  • T Offline
    T Offline
    tomasantunes
    wrote on last edited by tomasantunes
    #1

    My program crashes when I call this method. I'm trying to make graphic effect on an image.

    void MainWindow::stripesOk()
    {
        int nodeHeight = stripesDialog->nodeHeight;
        double division = imageObject->height() / nodeHeight;
        int totalNodes = qFloor(division);
        targetImage = new QImage(imageObject->size(), QImage::Format_ARGB32);
    
        painter = new QPainter(targetImage);
    
        for(int i = 0;i < totalNodes; i++)
        {
            int x = 0;
            int y = i * nodeHeight;
            int width = imageObject->width();
            int shift = stripesDialog->shift;
            int a = shift - (2 * shift);
            int b = shift;
            int randomShift = randomInterval(a,b);
            painter->drawImage(randomShift,y,*imageObject,x,y,width,nodeHeight);
        }
    
        imageObject = targetImage;
    }
    
    mrjjM 1 Reply Last reply
    0
    • T tomasantunes

      My program crashes when I call this method. I'm trying to make graphic effect on an image.

      void MainWindow::stripesOk()
      {
          int nodeHeight = stripesDialog->nodeHeight;
          double division = imageObject->height() / nodeHeight;
          int totalNodes = qFloor(division);
          targetImage = new QImage(imageObject->size(), QImage::Format_ARGB32);
      
          painter = new QPainter(targetImage);
      
          for(int i = 0;i < totalNodes; i++)
          {
              int x = 0;
              int y = i * nodeHeight;
              int width = imageObject->width();
              int shift = stripesDialog->shift;
              int a = shift - (2 * shift);
              int b = shift;
              int randomShift = randomInterval(a,b);
              painter->drawImage(randomShift,y,*imageObject,x,y,width,nodeHeight);
          }
      
          imageObject = targetImage;
      }
      
      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @tomasantunes

      Hi its hard to guess. You are 100% sure nodeHeight is not zero ?

      Also if you start with debug, and place break point at first line, you can single step and see
      which line that does the crash.

      T 1 Reply Last reply
      1
      • mrjjM mrjj

        @tomasantunes

        Hi its hard to guess. You are 100% sure nodeHeight is not zero ?

        Also if you start with debug, and place break point at first line, you can single step and see
        which line that does the crash.

        T Offline
        T Offline
        tomasantunes
        wrote on last edited by
        #3

        thanks, the variables were not being set properly, so they were at 0 indeed.

        the program is not crashing anymore, but I am only getting a blank image.

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          yoavmil
          wrote on last edited by
          #4

          I think you may be using painter->drawImage wrong. try using the defualt values for all the params except the first 3. then see what happens.

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

            Hi,

            Did you check the value of totalNodes ? Does the variables you use for drawImage have meaningful values ?

            By the way, why allocate your QImage object on the heap ? That's not needed, furthermore, from the looks of it, you have a memory leak since you don't delete imageObject before replacing it with targetImage.

            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
            1
            • T Offline
              T Offline
              tomasantunes
              wrote on last edited by
              #6

              solved, had to check another variable . thanks all

              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