Page 1 of 2 12 LastLast
Results 1 to 20 of 31

Thread: Image processing error

  1. #1

    Default Image processing error

    Hi everyone. I have a problem, I'm creating a simple Image Processing app, at part of brightness adjustment i can't run this function, when it's called then app will be crashed. I have two forms, one of form is mainwindow, one else is sub form to adjust brightness.

    Qt Code:
    1. //mainwindow.cpp
    2.  
    3. void MainWindow::brightnessProcessing(int value)
    4. {
    5. QImage image = imageLabel->pixmap()->toImage();
    6. int w = image.width();
    7. int h = image.height();
    8. QColor c;
    9. int r, g, b;
    10. for(int i=0; i<h; i++)
    11. for(int j=0; j<w; j++) {
    12. c = image.pixel(i, j);
    13. r = c.red()+value;
    14. g = c.green()+value;
    15. b = c.blue()+value;
    16. image.setPixel(i, j, qRgb(r, g, b));
    17. }
    18. imageLabel->setPixmap(QPixmap::fromImage(image));
    19. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //mainwindow.h
    2.  
    3. #ifndef MAINWINDOW_H
    4. #define MAINWINDOW_H
    5.  
    6. #include <QMainWindow>
    7. #include <QtWidgets>
    8.  
    9. namespace Ui {
    10. class MainWindow;
    11. }
    12.  
    13. class MainWindow : public QMainWindow
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. explicit MainWindow(QWidget *parent = 0);
    19. ~MainWindow();
    20. void brightnessProcessing(int value);
    21.  
    22. private slots:
    23. ..........
    24.  
    25. private:
    26. Ui::MainWindow *ui;
    27. QImage *image;
    28. QLabel *imageLabel;
    29. QScrollArea *scrollArea;
    30. QScrollBar *scrollBar;
    31. double scaleFactor;
    32.  
    33. void scaleImage(double factor);
    34. void adjustScrollBar(QScrollBar *scrollBar, double factor);
    35. };
    36.  
    37. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //brightnesscontrast.cpp
    2.  
    3. void BrightnessContrast::on_horizontalSliderBrightness_valueChanged(int value)
    4. {
    5. ui->lineEditBrightness->setText(QString::number(value));
    6. respond.brightnessProcessing(value);
    7. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //brightnesscontrast.h
    2.  
    3. #ifndef BRIGHTNESSCONTRAST_H
    4. #define BRIGHTNESSCONTRAST_H
    5.  
    6. #include <QDialog>
    7. #include <QtWidgets>
    8. #include "mainwindow.h"
    9.  
    10. namespace Ui {
    11. class BrightnessContrast;
    12. }
    13.  
    14. class BrightnessContrast : public QDialog
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. explicit BrightnessContrast(QWidget *parent = 0);
    20. ~BrightnessContrast();
    21.  
    22. private slots:
    23. void on_horizontalSliderBrightness_valueChanged(int value);
    24.  
    25. void on_horizontalSliderContrast_valueChanged(int value);
    26.  
    27. private:
    28. Ui::BrightnessContrast *ui;
    29. MainWindow respond;
    30. };
    31.  
    32. #endif // BRIGHTNESSCONTRAST_H
    To copy to clipboard, switch view to plain text mode 

    anyhelp!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Image processing error

    Run your program in your debugger and determine where your program crashes. Then work the conditions that cause it to crash there.

    Having an instance of the MainWindow in your dialog as a member variable is unusual.
    What happens when the existing red, green, or blue value is 255?

  3. #3

    Default Re: Image processing error

    I have run my program in debugger, have identified where my program crashes but i don't understand error parameters means what. So can't fix to error
    it here


    i also have edited member variables
    Qt Code:
    1. r = qBound<int>(0, c.red() + value, 255);
    2. g = qBound<int>(0, c.green() + value, 255);
    3. b = qBound<int>(0, c.blue() + value, 255);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Image processing error

    Quote Originally Posted by bachkimfly View Post
    I have run my program in debugger, have identified where my program crashes but i don't understand error parameters means what. So can't fix to error
    it here
    And since you don't tell us the error we can't help you either.

    Is imageLabel a valid pointer?

    Cheers,
    _

  5. #5

    Default Re: Image processing error

    Quote Originally Posted by anda_skoa View Post
    And since you don't tell us the error we can't help you either.

    Is imageLabel a valid pointer?

    Cheers,
    _
    Actually, I can't determine correct error, if that be can then I used quick search in net. I have run debugger and output above, hope it is useful.
    Yes, imageLabel is a valid pointer!
    Last edited by bachkimfly; 6th October 2013 at 11:02.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Image processing error

    Post the backtrace.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7

    Default Re: Image processing error

    backtrace for 4 breakpoints here:
    Qt Code:
    1. #2 0x0000000000406a40 in MainWindow::brightnessProcessing (this=0x7fffffffc838, value=1) at ../../qt workspace/Auroras/mainwindow.cpp:161
    2. image = <incomplete type>
    3. w = 32767
    4. c = {cspec = 4294952960, ct = {argb = {alpha = 32767, red = 0, green = 49696, blue = 196, pad = 0}, ahsv = {alpha = 32767, hue = 0, saturation = 49696, value = 196, pad = 0}, acmyk = {alpha = 32767, cyan = 0, magenta = 49696, yellow = 196, black = 0}, ahsl = {alpha = 32767, hue = 0, saturation = 49696, lightness = 196, pad = 0}, array = {32767, 0, 49696, 196, 0}}}
    5. g = 4232186
    6. h = -20672
    7. r = 32767
    8. b = 0
    9. #3 0x000000000040973c in BrightnessContrast::on_horizontalSliderBrightness_valueChanged (this=0x7fffffffc800, value=1) at ../../qt workspace/Auroras/brightnesscontrast.cpp:19
    10. No locals.
    11. #4 0x000000000040a5c5 in BrightnessContrast::qt_static_metacall (_o=0x7fffffffc800, _c=QMetaObject::InvokeMetaMethod, _id=0, _a=0x7fffffffb1c0) at moc_brightnesscontrast.cpp:73
    12. _t = 0x7fffffffc800
    13. #5 0x000000000040a6da in BrightnessContrast::qt_metacall (this=0x7fffffffc800, _c=QMetaObject::InvokeMetaMethod, _id=0, _a=0x7fffffffb1c0) at moc_brightnesscontrast.cpp:106
    14. No locals.
    To copy to clipboard, switch view to plain text mode 
    Last edited by bachkimfly; 6th October 2013 at 21:18.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Image processing error

    Seems like BrightnessContrast instance is an invalid pointer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9

    Default Re: Image processing error

    I import mainwindow into BrightnessContrast and declare:
    Qt Code:
    1. MainWindow respond;
    2. respond.brightnessProcessing(value);
    To copy to clipboard, switch view to plain text mode 
    This right?
    Last edited by bachkimfly; 6th October 2013 at 20:08.

  10. #10

    Default Re: Image processing error

    I posted backtrace wrong, I editted in #7

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Image processing error

    Could you explain why you did the thing Chris pointed out a couple of posts ago -- made MainWindow a member variable of a QDialog subclass?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12

    Default Re: Image processing error

    Can you give me a few link? I not yet reat it.
    ------------------------------------

    I'm trying "made MainWindow a member variable of a QDialog subclass"
    Last edited by bachkimfly; 6th October 2013 at 21:57.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Image processing error

    Quote Originally Posted by bachkimfly View Post
    I'm trying "made MainWindow a member variable of a QDialog subclass"
    Yes, we can see that. But why are you trying to do this?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14

    Default Re: Image processing error

    If don't made MainWindow a member variable of a QDialog, how to can executable event in QDialog. So what is your idea?

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Image processing error

    Quote Originally Posted by bachkimfly View Post
    If don't made MainWindow a member variable of a QDialog, how to can executable event in QDialog.
    I don't understand what you mean.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16

    Default Re: Image processing error

    I want to catch event slider value changed, but brightness processing function which at MainWindow, if don't made MainWindow as a member variable of a BrightnessContrast dialog, i dont know to executable event slider value changed. your idea!

    P/s: now, it's 5:22 AM, a tonight don't sleep, i want to go to sleep

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Image processing error

    Quote Originally Posted by bachkimfly View Post
    I want to catch event slider value changed, but brightness processing function which at MainWindow, if don't made MainWindow as a member variable of a BrightnessContrast dialog, i dont know to executable event slider value changed. your idea!
    Don't you already have an instance of the main window which launched the dialog? Do you understand the difference between a class and an instance of a class?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #18

    Default Re: Image processing error

    Alright! I need have to initialize object of MainWindow class, right?. I asked in #9.
    So what is I can understand for "made MainWindow a member variable of a QDialog subclass". Patently, I misconstrued.

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Image processing error

    Quote Originally Posted by bachkimfly View Post
    Alright! I need have to initialize object of MainWindow class, right?
    No, I'm assuming you already have such an object somewhere.

    Let's make a deal - if you keep ignoring my questions, I will start ignoring yours.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #20

    Default Re: Image processing error

    Quote Originally Posted by wysota View Post
    No, I'm assuming you already have such an object somewhere.

    Let's make a deal - if you keep ignoring my questions, I will start ignoring yours.
    I don't ignore, I answered by the question "I need have to initialize object of MainWindow class, right?". That means I don't have an instance of the main window which launched the dialog and I understand the difference between a class and an instance of a class. I think so.

    But I feel we are going around.

Similar Threads

  1. Replies: 4
    Last Post: 11th January 2013, 02:06
  2. Replies: 1
    Last Post: 13th December 2010, 12:19
  3. image processing
    By IRON_MAN in forum Qt Programming
    Replies: 4
    Last Post: 18th November 2009, 13:37
  4. Image processing
    By NicNac in forum Newbie
    Replies: 25
    Last Post: 2nd November 2008, 10:05
  5. Image Processing using Qt
    By danielperaza in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2008, 18:15

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.