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. How to include .txt on Qt
Forum Update on Monday, May 27th 2025

How to include .txt on Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
196 Posts 11 Posters 135.2k Views
  • 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.
  • P Offline
    P Offline
    Payx
    wrote on 30 Dec 2016, 15:46 last edited by
    #89

    Thanks it compile,

    the problem is that my window crash when i push the boutton who execute
    " Remplissage(pixi, QPoint(i, j), QSize(z, z), Couleurdominante(pixi, QPoint(i, j), QSize(z, z)));
    "
    ^^

    maybe enough things to do ?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 30 Dec 2016, 15:59 last edited by
      #90

      Well since you know what function it is, simply set a break point and single step through the code.
      That way it will clearly show what line it crashes on. ;)

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Payx
        wrote on 30 Dec 2016, 16:20 last edited by
        #91

        It's not crash, the program run at infinity and do nothing

        M 1 Reply Last reply 30 Dec 2016, 16:33
        0
        • P Payx
          30 Dec 2016, 16:20

          It's not crash, the program run at infinity and do nothing

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 30 Dec 2016, 16:33 last edited by
          #92

          @Payx
          well that will also be really clear from single stepping :)

          1 Reply Last reply
          1
          • P Offline
            P Offline
            Payx
            wrote on 30 Dec 2016, 16:59 last edited by Payx
            #93

            I placed breakpoint on

              for(int x = topLeft.x(); x < maxX; ++x) {
                for(int y = topLeft.y(); y < maxY; ++y) {
                  image.setPixelColor(x, y, colour);
            
                  foreach( QRgb key, Costs.keys() ) {
                    QColor BaseColor( key );
                    if (Costs.contains( colour.rgb() ) || IsCloseColor(BaseColor, colour) )  {
                      CostInfo& ci = Costs[colour.rgb()];
                      int Cost = ci.Cost;
                      QPixmap pix( ci.ImageName );
                    }
            
            

            because its new and before it worked.

            And nothing who looks like a crash happened. So i don't understand, maybe it is just a big picture (540 * 540) and the app have difficult to do the code

            EDIT : i tried to increase the rectangle size, it worked.

            but dont replace the color by a picture

            and it say that int cost is an unused variable

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 30 Dec 2016, 18:00 last edited by
              #94

              Hi
              In the inner
              CostInfo& ci = Costs[colour.rgb()];
              int Cost = ci.Cost; // not used for anything
              QPixmap pix( ci.ImageName ); // not used for anything
              }

              it was just for getting the data from the Costs qmap.
              You still need to code what ever you want to do with it :)
              Currently it just check if color is a match and even if yes, then nothing.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Payx
                wrote on 30 Dec 2016, 18:08 last edited by Payx
                #95

                so if i understood well

                int Cost = ci.Cost; /// the Cost in my Qmap
                QPixmap pix( ci.ImageName ); /// the picture into a Pixmap

                The problem is that the rectangle that i use to calcul the DominantColor isn't a Label or something, so how can i replace a picture into a virtual rectangle ?

                M 1 Reply Last reply 30 Dec 2016, 22:24
                0
                • P Payx
                  30 Dec 2016, 18:08

                  so if i understood well

                  int Cost = ci.Cost; /// the Cost in my Qmap
                  QPixmap pix( ci.ImageName ); /// the picture into a Pixmap

                  The problem is that the rectangle that i use to calcul the DominantColor isn't a Label or something, so how can i replace a picture into a virtual rectangle ?

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 30 Dec 2016, 22:24 last edited by
                  #96

                  @Payx
                  Yes those are the values from the qmap.

                  • so how can i replace a picture into a virtual rectangle

                  Sorry but Im not sure what kind of operation you want to do.
                  For each dominánt color for an area. you want to paint all of that area
                  with this color? Like paint 0,0,40,40 with same color. ?

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Payx
                    wrote on 30 Dec 2016, 22:30 last edited by
                    #97

                    My program already do that :

                    http://hpics.li/c00cce7

                    but what i want is that for each rectangle that my picture have, it will replace this rectangle of color by a picture in my QMap (like if the rectangle's color is near the red, it will replace by the picture fraise.png and add a Cost)

                    M 1 Reply Last reply 30 Dec 2016, 22:34
                    0
                    • P Payx
                      30 Dec 2016, 22:30

                      My program already do that :

                      http://hpics.li/c00cce7

                      but what i want is that for each rectangle that my picture have, it will replace this rectangle of color by a picture in my QMap (like if the rectangle's color is near the red, it will replace by the picture fraise.png and add a Cost)

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 30 Dec 2016, 22:34 last edited by
                      #98

                      @Payx
                      You mean that the red squares would be pictures instead?
                      The painter has drawPixmap
                      http://doc.qt.io/qt-5/qpainter.html#drawPixmap
                      You can fit the image to the rect.

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        Payx
                        wrote on 30 Dec 2016, 23:04 last edited by
                        #99

                        All square would be picture, the picture depends of the color.

                        If its red we see in the QMap that the picture is fraise.png
                        if its green -> balle verte.png

                        i think i dont need "QRectF target" or "source"

                        because i have already this

                          for(int x = topLeft.x(); x < maxX; ++x) {
                            for(int y = topLeft.y(); y < maxY; ++y)
                        

                        when im on the for i'm already in the square.

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 31 Dec 2016, 09:28 last edited by
                          #100

                          ok. that sounds fine.
                          I assume you need to scale the pictures down to fit in the
                          area. ?
                          You can use scaled function.

                          QPixmap scaledPix = pix.scaled(   WIDTH, HEIGHT
                                                         Qt::KeepAspectRatio,
                                                         Qt::SmoothTransformation
                                                         );
                          
                          painter.drawPixmap(QPoint(), scaledPix);
                          
                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            Payx
                            wrote on 31 Dec 2016, 14:34 last edited by Payx
                            #101

                            So i have to rezise the picture or it will do automaticaly ?

                            i don't understand what the function do

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 31 Dec 2016, 14:52 last edited by
                              #102

                              No, you will have to resize it, else it will be exactly as in the file.( I assume too big)
                              the scaled function returns a copy of the pixmap that is scaled to
                              WIDTH, HEIGHT. so it will fit in your area.

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                Payx
                                wrote on 31 Dec 2016, 15:22 last edited by
                                #103

                                so if my rectangle is 8*8 tell me if it's correct :

                                QPixmap scaledPix = pix.scaled(   8, 8
                                                               Qt::KeepAspectRatio,
                                                               Qt::SmoothTransformation
                                                               );
                                
                                painter.drawPixmap(QPoint(i,j), scaledPix);
                                

                                just that ?

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 1 Jan 2017, 01:03 last edited by mrjj 1 Jan 2017, 01:05
                                  #104

                                  Yes , that should draw image as 8x8 at i,j.
                                  Note the flag Qt::KeepAspectRatio which means it might not be 8x8 directly but
                                  maybe 8x6 if the original images was not square. AspectRatio means keep the relation between height and width.

                                  A 1 Reply Last reply 1 Jan 2017, 04:17
                                  0
                                  • M mrjj
                                    1 Jan 2017, 01:03

                                    Yes , that should draw image as 8x8 at i,j.
                                    Note the flag Qt::KeepAspectRatio which means it might not be 8x8 directly but
                                    maybe 8x6 if the original images was not square. AspectRatio means keep the relation between height and width.

                                    A Offline
                                    A Offline
                                    ambershark
                                    wrote on 1 Jan 2017, 04:17 last edited by
                                    #105

                                    @mrjj 104 posts on this thread... you are a patient person mrjj. ;) I would have just written the program for him by now, lol.

                                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                                    P 1 Reply Last reply 1 Jan 2017, 12:00
                                    0
                                    • A ambershark
                                      1 Jan 2017, 04:17

                                      @mrjj 104 posts on this thread... you are a patient person mrjj. ;) I would have just written the program for him by now, lol.

                                      P Offline
                                      P Offline
                                      Payx
                                      wrote on 1 Jan 2017, 12:00 last edited by Payx 1 Jan 2017, 12:22
                                      #106

                                      @ambershark Lol

                                      I prefer learn instead of just don't understand what i'm doing, i know i'm very bad to programmation by now but maybe in few years i'il be like mrjj haha !

                                      for the QPoint, i use it here :

                                      void MainWindow::on_push2_clicked()
                                      {
                                      
                                      
                                      	for (int i=0;i<pixi.width();i+=z){
                                      						 for (int j=0;j<pixi.height();j+=z){
                                      							 k=k+0.06;
                                      							Remplissage(pixi,QPoint(i,j),QSize(z,z),Couleurdominante(pixi,QPoint(i,j),QSize(z,z)));
                                      
                                      		}
                                      	}
                                      
                                      

                                      but i use the QPixmap scaledPix .....
                                      in my function

                                      void Remplissage(QImage& image, const QPoint& topLeft, const QSize& rectangle, const QColor& colour) {
                                      

                                      so it tell that j and i was not declared in this scope

                                      so i declared i and j in my .h

                                      #ifndef MAINWINDOW_H
                                      #define MAINWINDOW_H
                                      
                                      #include <QMainWindow>
                                      #include <QPixmap>
                                      #include <QPoint>
                                      #include <QSize>
                                      #include <iostream>
                                      #include <QMapIterator>
                                      #include <QMap>
                                      
                                      namespace Ui {
                                      class MainWindow;
                                      }
                                      
                                      struct CostInfo {
                                        QString ImageName;
                                        int     Cost;
                                      };
                                      
                                      int j;
                                      int i;
                                      
                                      class MainWindow : public QMainWindow {
                                        Q_OBJECT
                                      
                                       public:
                                        explicit MainWindow(QWidget* parent = 0);
                                      
                                        ~MainWindow();
                                      
                                       private slots:
                                        void on_push_clicked();
                                        void on_push2_clicked();
                                        void on_verticalSlider_sliderMoved(int position);
                                      
                                       private:
                                        Ui::MainWindow* ui;
                                        QImage pixi;
                                        QPixmap pixa;
                                        float k;
                                        int a;
                                      
                                      
                                        int z = 1;
                                        int b;
                                      };
                                      
                                      #endif // MAINWINDOW_HH
                                      
                                      

                                      it will work?

                                      //

                                      it tell that painter was not declared too, so i search to the QPainter class,

                                      it's "void QPainter::drawPixmap(const QPoint & point, const QPixmap & pixmap)" that i should use ?

                                      A 1 Reply Last reply 2 Jan 2017, 00:49
                                      0
                                      • M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 1 Jan 2017, 12:34 last edited by
                                        #107

                                        Hi
                                        hehe @ambershark , yes that would be faster but in this case,
                                        declaration and scopes are part of the exercise so hence the amount of posts. :)

                                        @Payx
                                        The j and is local variable in your for loops
                                        Yes it will work to make them member of the class but you actually give them to
                                        Remplissage via the QPoint(i,j)
                                        Remplissage(pixi,QPoint(i,j),QSize(z,z),Couleurdominante(pixi,QPoint(i,j),QSize(z,z)));
                                        so inside the Remplissage function, i and j are
                                        int i = topLeft.x();
                                        int j=topLeft.y();

                                        • it tell that painter was not declared too, so i search to the QPainter class,
                                          Did you #include<QPainter> ?

                                        Calling it like
                                        painter.drawPixmap(topLeft, scaledPix);
                                        should work.

                                        1 Reply Last reply
                                        0
                                        • P Offline
                                          P Offline
                                          Payx
                                          wrote on 1 Jan 2017, 13:09 last edited by
                                          #108

                                          Yes i have already test with include QPainter, same error ^^

                                          M 1 Reply Last reply 1 Jan 2017, 13:16
                                          0

                                          98/196

                                          30 Dec 2016, 22:34

                                          • Login

                                          • Login or register to search.
                                          98 out of 196
                                          • First post
                                            98/196
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved