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. Analysing an icon editor application
Forum Updated to NodeBB v4.3 + New Features

Analysing an icon editor application

Scheduled Pinned Locked Moved Solved General and Desktop
36 Posts 6 Posters 8.9k 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.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by tomy
    #1

    Hello,

    In the chapter 5 of the book C++ GUI Programming with Qt-4, 2nd Edition, I faced this example:

    main.cpp:

    #include <QApplication>
    #include "iconeditor.h"
    
    int main(int argc, char* argv[])
    {
        QApplication app(argc, argv);
    
        IconEditor iconEditor;
        iconEditor.setWindowTitle(QObject::tr("Icon Editor"));
        iconEditor.setIconImage(QImage(":/images/mouse.png"));
        iconEditor.show();
    
        return app.exec();
    }
    

    iconeditor.h:

    #ifndef ICONEDITOR_H
    #define ICONEDITOR_H
    
    #include <QColor>
    #include <QImage>
    #include <QWidget>
    
    class IconEditor : public QWidget
    {
        Q_OBJECT
        Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor)
        Q_PROPERTY(QImage iconImage READ iconImage WRITE setIconImage)
        Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor)
    
    public:
        IconEditor(QWidget *parent = 0);
    
        QColor penColor() const { return curColor; }
        QImage iconImage() const { return image; }
        int zoomFactor() const { return zoom; }
        void setPenColor(const QColor &newColor);
        void setIconImage(const QImage &newImage);
        void setZoomFactor(int newZoom);
    
        QSize sizeHint() const;
    
        ~IconEditor();
    
    protected:
        void mousePressEvent(QMouseEvent *event);
        void mouseMoveEvent(QMouseEvent *event);
        void paintEvent(QPaintEvent *event);
    
    private:
        void setImagePixel(const QPoint &pos, bool opaque);
        QRect pixelRect(int i, int j) const;
    
        QColor curColor;
        QImage image;
        int zoom;
    };
    
    #endif // ICONEDITOR_H
    

    iconeditor.cpp:

    #include <QtWidgets>
    #include "iconeditor.h"
    
    IconEditor::IconEditor(QWidget *parent)
        : QWidget(parent)
    {
        setAttribute(Qt::WA_StaticContents);
        setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    
        curColor = Qt::blue;
        zoom = 8;
    
        image = QImage(16, 16, QImage::Format_ARGB32);
        image.fill(qRgba(0, 0, 0, 0));
    }
    
    //*******************************************************
    
    void IconEditor::setPenColor(const QColor& newColor)
    {
        curColor = newColor;
    }
    
    //**************************************************
    
    void IconEditor::setZoomFactor(int newZoom)
    {
        if (newZoom < 1)
            newZoom = 1;
    
        if (newZoom != zoom) {
            zoom = newZoom;
            update();
            updateGeometry();
        }
    }
    
    //***********************************************************
    
    void IconEditor::setIconImage(const QImage &newImage)
    {
        if (newImage != image) {
            image = newImage.convertToFormat(QImage::Format_ARGB32);
            update();
            updateGeometry();
        }
    }
    
    //********************************************
    
    QSize IconEditor::sizeHint() const
    {
        QSize size = zoom * image.size();
        if (zoom >= 3)
            size += QSize(1, 1);
        return size;
    }
    
    //*******************************************
    
    void IconEditor::paintEvent(QPaintEvent *event)
    {
        QPainter painter(this);
        qDebug() << image.height() << ' ' << image.width() <<endl;
        if(zoom >= 3)
          {
            painter.setPen(palette().foreground().color());
            for(int i = 0; i< image.width(); ++i)
                painter.drawLine(zoom * i, 0, zoom *i, zoom * image.height());
    
            for(int j = 0; j<image.height(); ++j)
                painter.drawLine(0, zoom * j, zoom * image.width(), zoom * j);
          }
    
        for(int i = 0; i<image.width(); ++i)
            for(int j = 0; j < image.height(); ++j)
            {
                QRect rect = pixelRect(i, j);
                  if(!event->region().intersected(rect).isEmpty())
                  {
                     QColor color = QColor::fromRgba(image.pixel(i, j));
                      if(color.alpha() < 255)
                         painter.fillRect(rect, Qt::white);
                      painter.fillRect(rect, color);
                  }
            }
    }
    
    //************************************************
    
    QRect IconEditor::pixelRect(int i, int j) const
    {
        if( zoom >= 3)
            return QRect(zoom * i + 1, zoom * j + 1, zoom-1, zoom-1);
        else
            return QRect(zoom * i, zoom * j, zoom , zoom);
    }
    
    //**************************************************
    
    void IconEditor::mousePressEvent(QMouseEvent *event)
    {
        if(event->button() == Qt::LeftButton)
            setImagePixel(event->pos(), true);
        else if(event->button() == Qt::RightButton)
            setImagePixel(event->pos(), false);
    }
    
    //************************************************
    
    void IconEditor::mouseMoveEvent(QMouseEvent *event)
    {
        if(event->buttons() & Qt::LeftButton)
            setImagePixel(event->pos(), true);
        else if(event->buttons() & Qt::RightButton)
            setImagePixel(event->pos(), false);
    }
    
    //*********************************************************
    
    void IconEditor::setImagePixel(const QPoint &pos, bool opaque)
    {
        int i = pos.x() / zoom;
        int j = pos.y() / zoom;
    
        if(image.rect().contains(i, j)) {
            if(opaque)
                image.setPixel(i, j, penColor().rgba());
            else
                image.setPixel(i, j, qRgba(0 , 0, 0, 0));
        update(pixelRect(i, j));
        }
    }
    
    //***************************************************
    
    IconEditor::~IconEditor() { }
    
    

    I read that part of the book two times but haven't understood the example completely, yet!

    The issue is the so-called statements execution chain!
    I think just like C++ programs, all Qt programs start from main.cpp (OK, I know Qt is only a library!)

    If so, the program starts from the first statement: IconEditor iconEditor; in main.cpp, an instantiation. It was the first step. The next step is executing setAttribute(Qt::WA_StaticContents); in the constructor.

    Well, I want to continue to state my thought but one question here, have my thoughts been right up to this point?

    The subject is that if I know how the statements sequence is executed I figure the program out better.

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

      Hi,

      Technically, no. The first statement is the app object creation which does a bunch of Qt internal initialisation. Then you have an object of type IconEditor that is created. And the first line is not setAttribute but : QWidget(parent) which is the call to the base class constructor. Only then will setAttribute be called.

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

      tomyT 1 Reply Last reply
      3
      • tomyT tomy

        Hello,

        In the chapter 5 of the book C++ GUI Programming with Qt-4, 2nd Edition, I faced this example:

        main.cpp:

        #include <QApplication>
        #include "iconeditor.h"
        
        int main(int argc, char* argv[])
        {
            QApplication app(argc, argv);
        
            IconEditor iconEditor;
            iconEditor.setWindowTitle(QObject::tr("Icon Editor"));
            iconEditor.setIconImage(QImage(":/images/mouse.png"));
            iconEditor.show();
        
            return app.exec();
        }
        

        iconeditor.h:

        #ifndef ICONEDITOR_H
        #define ICONEDITOR_H
        
        #include <QColor>
        #include <QImage>
        #include <QWidget>
        
        class IconEditor : public QWidget
        {
            Q_OBJECT
            Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor)
            Q_PROPERTY(QImage iconImage READ iconImage WRITE setIconImage)
            Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor)
        
        public:
            IconEditor(QWidget *parent = 0);
        
            QColor penColor() const { return curColor; }
            QImage iconImage() const { return image; }
            int zoomFactor() const { return zoom; }
            void setPenColor(const QColor &newColor);
            void setIconImage(const QImage &newImage);
            void setZoomFactor(int newZoom);
        
            QSize sizeHint() const;
        
            ~IconEditor();
        
        protected:
            void mousePressEvent(QMouseEvent *event);
            void mouseMoveEvent(QMouseEvent *event);
            void paintEvent(QPaintEvent *event);
        
        private:
            void setImagePixel(const QPoint &pos, bool opaque);
            QRect pixelRect(int i, int j) const;
        
            QColor curColor;
            QImage image;
            int zoom;
        };
        
        #endif // ICONEDITOR_H
        

        iconeditor.cpp:

        #include <QtWidgets>
        #include "iconeditor.h"
        
        IconEditor::IconEditor(QWidget *parent)
            : QWidget(parent)
        {
            setAttribute(Qt::WA_StaticContents);
            setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
        
            curColor = Qt::blue;
            zoom = 8;
        
            image = QImage(16, 16, QImage::Format_ARGB32);
            image.fill(qRgba(0, 0, 0, 0));
        }
        
        //*******************************************************
        
        void IconEditor::setPenColor(const QColor& newColor)
        {
            curColor = newColor;
        }
        
        //**************************************************
        
        void IconEditor::setZoomFactor(int newZoom)
        {
            if (newZoom < 1)
                newZoom = 1;
        
            if (newZoom != zoom) {
                zoom = newZoom;
                update();
                updateGeometry();
            }
        }
        
        //***********************************************************
        
        void IconEditor::setIconImage(const QImage &newImage)
        {
            if (newImage != image) {
                image = newImage.convertToFormat(QImage::Format_ARGB32);
                update();
                updateGeometry();
            }
        }
        
        //********************************************
        
        QSize IconEditor::sizeHint() const
        {
            QSize size = zoom * image.size();
            if (zoom >= 3)
                size += QSize(1, 1);
            return size;
        }
        
        //*******************************************
        
        void IconEditor::paintEvent(QPaintEvent *event)
        {
            QPainter painter(this);
            qDebug() << image.height() << ' ' << image.width() <<endl;
            if(zoom >= 3)
              {
                painter.setPen(palette().foreground().color());
                for(int i = 0; i< image.width(); ++i)
                    painter.drawLine(zoom * i, 0, zoom *i, zoom * image.height());
        
                for(int j = 0; j<image.height(); ++j)
                    painter.drawLine(0, zoom * j, zoom * image.width(), zoom * j);
              }
        
            for(int i = 0; i<image.width(); ++i)
                for(int j = 0; j < image.height(); ++j)
                {
                    QRect rect = pixelRect(i, j);
                      if(!event->region().intersected(rect).isEmpty())
                      {
                         QColor color = QColor::fromRgba(image.pixel(i, j));
                          if(color.alpha() < 255)
                             painter.fillRect(rect, Qt::white);
                          painter.fillRect(rect, color);
                      }
                }
        }
        
        //************************************************
        
        QRect IconEditor::pixelRect(int i, int j) const
        {
            if( zoom >= 3)
                return QRect(zoom * i + 1, zoom * j + 1, zoom-1, zoom-1);
            else
                return QRect(zoom * i, zoom * j, zoom , zoom);
        }
        
        //**************************************************
        
        void IconEditor::mousePressEvent(QMouseEvent *event)
        {
            if(event->button() == Qt::LeftButton)
                setImagePixel(event->pos(), true);
            else if(event->button() == Qt::RightButton)
                setImagePixel(event->pos(), false);
        }
        
        //************************************************
        
        void IconEditor::mouseMoveEvent(QMouseEvent *event)
        {
            if(event->buttons() & Qt::LeftButton)
                setImagePixel(event->pos(), true);
            else if(event->buttons() & Qt::RightButton)
                setImagePixel(event->pos(), false);
        }
        
        //*********************************************************
        
        void IconEditor::setImagePixel(const QPoint &pos, bool opaque)
        {
            int i = pos.x() / zoom;
            int j = pos.y() / zoom;
        
            if(image.rect().contains(i, j)) {
                if(opaque)
                    image.setPixel(i, j, penColor().rgba());
                else
                    image.setPixel(i, j, qRgba(0 , 0, 0, 0));
            update(pixelRect(i, j));
            }
        }
        
        //***************************************************
        
        IconEditor::~IconEditor() { }
        
        

        I read that part of the book two times but haven't understood the example completely, yet!

        The issue is the so-called statements execution chain!
        I think just like C++ programs, all Qt programs start from main.cpp (OK, I know Qt is only a library!)

        If so, the program starts from the first statement: IconEditor iconEditor; in main.cpp, an instantiation. It was the first step. The next step is executing setAttribute(Qt::WA_StaticContents); in the constructor.

        Well, I want to continue to state my thought but one question here, have my thoughts been right up to this point?

        The subject is that if I know how the statements sequence is executed I figure the program out better.

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @tomy Well, a C/C++ program starts with main. In this case the next thing is

        QApplication app(argc, argv);
        

        then

        IconEditor iconEditor;
        

        which means that the constructor of IconEditor is executed. Then the base class constructor is executed (QWidget(parent)) and then setAttribute(Qt::WA_StaticContents);

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

        1 Reply Last reply
        2
        • SGaistS SGaist

          Hi,

          Technically, no. The first statement is the app object creation which does a bunch of Qt internal initialisation. Then you have an object of type IconEditor that is created. And the first line is not setAttribute but : QWidget(parent) which is the call to the base class constructor. Only then will setAttribute be called.

          tomyT Offline
          tomyT Offline
          tomy
          wrote on last edited by
          #4

          @SGaist @jsulm Thanks.

          The first statement is the app object creation which does a bunch of Qt internal initialisation.

          but : QWidget(parent) which is the call to the base class constructor.

          Yes, these are facts but do we need to care about them?

          On setAttribute I got this from Help: Indicates that the widget contents are north-west aligned and static. On resize, such a widget will receive paint events only for parts of itself that are newly visible. This flag is set or cleared by the widget's author.

          There are two points: north-west alignment and static. For the static, we have the icon plus a grid. Do we have any copy to prevent them by making those two contents static? And whether we use the attribute or not the icon is north-west aligned and also no modification happens showing the effect of not using that attribute!!

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

            Yes you do, ignoring proper construction can lead to all sort of bad things.

            That attribute explain that there will be no repaint done unless something new is visible so you won't see any difference changing just that flag. It's on the painting level that the difference happens.

            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
            2
            • tomyT Offline
              tomyT Offline
              tomy
              wrote on last edited by
              #6

              @SGaist
              So since we don't have any new image we won't see any repaint making that attribute useless in this example. Besides the north-west alignment is right without it as well. (1)

              Apart from that, another useless (seemingly) code is:

              Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor)
              Q_PROPERTY(QImage iconImage READ iconImage WRITE setIconImage)
              Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor)
              

              The program work well with or without it as well! (2)
              I don't know why the author has used these in the program except for introducing them. So I think I can remove both (1) and (2) without any problem facing the program.

              1 Reply Last reply
              0
              • tomyT Offline
                tomyT Offline
                tomy
                wrote on last edited by tomy
                #7

                The next statement that is executed is: setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
                I looked its meaning up on Help and it speaks about preferences. The book also says: The widget
                can be stretched if required, but it should never shrink below the size hint.
                .

                sizeHint() is also:

                QSize IconEditor::sizeHint() const
                {
                    QSize size = zoom * image.size();
                    if (zoom >= 3)
                        size += QSize(1, 1);
                    return size;
                }
                

                The image is multiplied by the zoom factor (8).
                So the widget, the window containing the grid layout and the image should not be shrunk. But in practice we can make it bigger and also smaller!
                EDITED:

                The next steps are: curColor = Qt::blue; zoom = 8;
                Then: image = QImage(16, 16, QImage::Format_ARGB32);, that using this initialisation we actually make a 16*16 pixels room for the image variable. In image.fill(qRgba(0, 0, 0, 0)); we make that room transparent (clear or having nothing ready to get the real icon image).

                The next statement will be iconEditor.setIconImage(QImage(":/images/mouse.png")); in main.cpp.

                Right up to here?

                jsulmJ 1 Reply Last reply
                0
                • tomyT tomy

                  The next statement that is executed is: setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
                  I looked its meaning up on Help and it speaks about preferences. The book also says: The widget
                  can be stretched if required, but it should never shrink below the size hint.
                  .

                  sizeHint() is also:

                  QSize IconEditor::sizeHint() const
                  {
                      QSize size = zoom * image.size();
                      if (zoom >= 3)
                          size += QSize(1, 1);
                      return size;
                  }
                  

                  The image is multiplied by the zoom factor (8).
                  So the widget, the window containing the grid layout and the image should not be shrunk. But in practice we can make it bigger and also smaller!
                  EDITED:

                  The next steps are: curColor = Qt::blue; zoom = 8;
                  Then: image = QImage(16, 16, QImage::Format_ARGB32);, that using this initialisation we actually make a 16*16 pixels room for the image variable. In image.fill(qRgba(0, 0, 0, 0)); we make that room transparent (clear or having nothing ready to get the real icon image).

                  The next statement will be iconEditor.setIconImage(QImage(":/images/mouse.png")); in main.cpp.

                  Right up to here?

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

                  @tomy Please check Qt documentation: http://doc.qt.io/qt-5/qwidget.html#sizeHint-prop
                  It says:
                  "This property holds the recommended size for the widget"
                  So, it is recommended size not minimal.
                  Even the description in the book doesn't say that it is not allowed to go bellow the sizeHint:
                  "but it should never shrink below the size hint".

                  "Right up to here?" - what do you mean?

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

                  tomyT 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @tomy Please check Qt documentation: http://doc.qt.io/qt-5/qwidget.html#sizeHint-prop
                    It says:
                    "This property holds the recommended size for the widget"
                    So, it is recommended size not minimal.
                    Even the description in the book doesn't say that it is not allowed to go bellow the sizeHint:
                    "but it should never shrink below the size hint".

                    "Right up to here?" - what do you mean?

                    tomyT Offline
                    tomyT Offline
                    tomy
                    wrote on last edited by
                    #9

                    @jsulm

                    "Right up to here?" - what do you mean?

                    I meant : was what I said/understood correct? (Mostly about the next statements)

                    mrjjM 1 Reply Last reply
                    0
                    • tomyT tomy

                      @jsulm

                      "Right up to here?" - what do you mean?

                      I meant : was what I said/understood correct? (Mostly about the next statements)

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @tomy

                      if you mean
                      QImage(16, 16, QImage::Format_ARGB32)

                      you create an image of size 16x16 with ARG32 format.

                      tomyT 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @tomy

                        if you mean
                        QImage(16, 16, QImage::Format_ARGB32)

                        you create an image of size 16x16 with ARG32 format.

                        tomyT Offline
                        tomyT Offline
                        tomy
                        wrote on last edited by
                        #11

                        @mrjj
                        No I meant: is iconEditor.setIconImage(QImage(":/images/mouse.png")); in main.cpp the next statement?
                        If so, then it goes to void IconEditor::setIconImage(const QImage &newImage). This function executes and finishes. But it's not clear from where the executor follows other statements, or, what is the next statement after this function?

                        We have several functions in the program, I want to know how they will be called.

                        mrjjM 1 Reply Last reply
                        0
                        • tomyT tomy

                          @mrjj
                          No I meant: is iconEditor.setIconImage(QImage(":/images/mouse.png")); in main.cpp the next statement?
                          If so, then it goes to void IconEditor::setIconImage(const QImage &newImage). This function executes and finishes. But it's not clear from where the executor follows other statements, or, what is the next statement after this function?

                          We have several functions in the program, I want to know how they will be called.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @tomy

                          Hi
                          if you right click on a function, you can select Find Usage
                          and it will all show places called / used.

                          You can also stand on a function and press F2 it will then go into that. You can then F2 other things it calls there.

                          J.HilkJ 1 Reply Last reply
                          3
                          • mrjjM mrjj

                            @tomy

                            Hi
                            if you right click on a function, you can select Find Usage
                            and it will all show places called / used.

                            You can also stand on a function and press F2 it will then go into that. You can then F2 other things it calls there.

                            J.HilkJ Online
                            J.HilkJ Online
                            J.Hilk
                            Moderators
                            wrote on last edited by
                            #13

                            @mrjj additionally to that, in one of the latest QCreator releases, ctrl + Leftclick can be used instead of F2.

                            A tiny bit more convenient in my opinion.


                            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                            Q: What's that?
                            A: It's blue light.
                            Q: What does it do?
                            A: It turns blue.

                            mrjjM 1 Reply Last reply
                            1
                            • J.HilkJ J.Hilk

                              @mrjj additionally to that, in one of the latest QCreator releases, ctrl + Leftclick can be used instead of F2.

                              A tiny bit more convenient in my opinion.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @J.Hilk

                              Absolutely and also holding ctrl+alt + click to open in spit window is really handy.

                              J.HilkJ 1 Reply Last reply
                              1
                              • mrjjM mrjj

                                @J.Hilk

                                Absolutely and also holding ctrl+alt + click to open in spit window is really handy.

                                J.HilkJ Online
                                J.HilkJ Online
                                J.Hilk
                                Moderators
                                wrote on last edited by
                                #15

                                @mrjj Wait, what !? I wasn't aware of that! Very very handy!

                                Thankfully with 4.4.1 my Creator doesnt bug out any longer when i have more than one window open. Previously any and all popups would no longer be shown. Aggravating but made me lookup and learn more shortcuts...


                                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                Q: What's that?
                                A: It's blue light.
                                Q: What does it do?
                                A: It turns blue.

                                mrjjM 1 Reply Last reply
                                0
                                • J.HilkJ J.Hilk

                                  @mrjj Wait, what !? I wasn't aware of that! Very very handy!

                                  Thankfully with 4.4.1 my Creator doesnt bug out any longer when i have more than one window open. Previously any and all popups would no longer be shown. Aggravating but made me lookup and learn more shortcuts...

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @J.Hilk
                                  Yep, now i only wish for a key that can open/close all comment sections in a file :)

                                  1 Reply Last reply
                                  0
                                  • tomyT Offline
                                    tomyT Offline
                                    tomy
                                    wrote on last edited by tomy
                                    #17

                                    Guys, I don't need these (I knew F2). I don't want to know where such a function is written or not, it's like ctrl+F. I want the sequence of the statements which are executed from the beginning of the program until end. You can also read prior posts as well.

                                    In Visual Studio 2017 when I code in C++, I put the cursor on the first statement of the main function and press Ctrl + F10 (Run to Cursor). And by pressing F10 (for executing a statement) and F11 (for going into the body of a function), it goes through the statements in the same way as they are executed by the compiler. So I will be aware of the process being done from start (where I pressed ctrl + F10) until end.

                                    Since I'm rather new in Qt, for being able to understand the program correctly, I need to know how the whole program runs.
                                    I hope I've made it clear now what I'm looking for.

                                    J.HilkJ 1 Reply Last reply
                                    0
                                    • tomyT tomy

                                      Guys, I don't need these (I knew F2). I don't want to know where such a function is written or not, it's like ctrl+F. I want the sequence of the statements which are executed from the beginning of the program until end. You can also read prior posts as well.

                                      In Visual Studio 2017 when I code in C++, I put the cursor on the first statement of the main function and press Ctrl + F10 (Run to Cursor). And by pressing F10 (for executing a statement) and F11 (for going into the body of a function), it goes through the statements in the same way as they are executed by the compiler. So I will be aware of the process being done from start (where I pressed ctrl + F10) until end.

                                      Since I'm rather new in Qt, for being able to understand the program correctly, I need to know how the whole program runs.
                                      I hope I've made it clear now what I'm looking for.

                                      J.HilkJ Online
                                      J.HilkJ Online
                                      J.Hilk
                                      Moderators
                                      wrote on last edited by
                                      #18

                                      @tomy mmh, ist that just a fancy way of setting a breakpoint and hitting F5 ? That you can do in QtCreator as well as in VS, even same short cuts.


                                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                      Q: What's that?
                                      A: It's blue light.
                                      Q: What does it do?
                                      A: It turns blue.

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

                                        Ah you ment while debugging.
                                        Just place break point and the call trace window will show the complete call tree.
                                        http://doc.qt.io/qtcreator/creator-debug-mode.html
                                        section Viewing Call Stack Trace

                                        1 Reply Last reply
                                        3
                                        • tomyT Offline
                                          tomyT Offline
                                          tomy
                                          wrote on last edited by tomy
                                          #20

                                          OK, I want to go through a program line-by-line or instruction-by-instruction. For that apparently I can use the debugger. For that the first thing is I think going to Window > Views. But Views is grayed out there!

                                          I also went to main.cpp and tried to trace the instructions by F10 and F11. This way, I only could go into the constructor by F11 on IconEditor iconEditor;. I still don't know how those several functions in iconeditor.cpp are called/used!

                                          0_1509027707561_Capture.PNG

                                          mrjjM C 2 Replies 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