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 Updated to NodeBB v4.3 + New Features

How to include .txt on Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
196 Posts 11 Posters 141.8k 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.
  • P Offline
    P Offline
    Payx
    wrote on 7 Jan 2017, 17:56 last edited by
    #130

    So i add the if :

    					if (pix.isNull()){
    					QPixmap pix(":/img/ballebleue.png");
    					};
    
    

    Same error as before "QPixmap::scaled: Pixmap is a null pixmap"

    M 1 Reply Last reply 7 Jan 2017, 17:58
    0
    • P Payx
      7 Jan 2017, 17:56

      So i add the if :

      					if (pix.isNull()){
      					QPixmap pix(":/img/ballebleue.png");
      					};
      
      

      Same error as before "QPixmap::scaled: Pixmap is a null pixmap"

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 7 Jan 2017, 17:58 last edited by
      #131

      @Payx said in How to include .txt on Qt:

      if (pix.isNull()){
      QPixmap pix(":/img/ballebleue.png");
      };

      Well that would not really change anything as you create a new local pix and its not related to the "pix" outside
      You should find out if its invalid and then why it is

      if (pix.isNull()){
      qDebug() << "yep its no good";
      return;
      };

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Payx
        wrote on 7 Jan 2017, 18:06 last edited by
        #132

        okay so i have that.

        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        QImage::pixel: coordinate (144,540) out of range
        QImage::pixel: coordinate (145,540) out of range
        QImage::pixel: coordinate (146,540) out of range
        QImage::pixel: coordinate (147,540) out of range
        QImage::pixel: coordinate (148,540) out of range
        QImage::pixel: coordinate (149,540) out of range
        QImage::pixel: coordinate (150,540) out of range
        QImage::pixel: coordinate (151,540) out of range
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        yep its no good
        QImage::pixel: coordinate (168,540) out of range
        QImage::pixel: coordinate (169,540) out of range
        QImage::pixel: coordinate (170,540) out of range
        QImage::pixel: coordinate (171,540) out of range
        QImage::pixel: coordinate (172,540) out of range
        QImage::pixel: coordinate (173,540) out of range
        QImage::pixel: coordinate (174,540) out of range
        QImage::pixel: coordinate (175,540) out of range
        QImage::pixel: coordinate (168,541) out of range
        QImage::pixel: coordinate (169,541) out of range
        QImage::pixel: coordinate (170,541) out of range
        QImage::pixel: coordinate (171,541) out of range
        QImage::pixel: coordinate (172,541) out of range
        QImage::pixel: coordinate (173,541) out of range
        QImage::pixel: coordinate (174,541) out of range
        QImage::pixel: coordinate (175,541) out of range
        QImage::pixel: coordinate (168,542) out of range
        QImage::pixel: coordinate (169,542) out of range
        QImage::pixel: coordinate (170,542) out of range
        QImage::pixel: coordinate (171,542) out of range
        QImage::pixel: coordinate (172,542) out of range
        QImage::pixel: coordinate (173,542) out of range
        QImage::pixel: coordinate (174,542) out of range
        
        

        that's mean that my pix is null right?

        M 1 Reply Last reply 7 Jan 2017, 18:07
        0
        • P Payx
          7 Jan 2017, 18:06

          okay so i have that.

          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          QImage::pixel: coordinate (144,540) out of range
          QImage::pixel: coordinate (145,540) out of range
          QImage::pixel: coordinate (146,540) out of range
          QImage::pixel: coordinate (147,540) out of range
          QImage::pixel: coordinate (148,540) out of range
          QImage::pixel: coordinate (149,540) out of range
          QImage::pixel: coordinate (150,540) out of range
          QImage::pixel: coordinate (151,540) out of range
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          yep its no good
          QImage::pixel: coordinate (168,540) out of range
          QImage::pixel: coordinate (169,540) out of range
          QImage::pixel: coordinate (170,540) out of range
          QImage::pixel: coordinate (171,540) out of range
          QImage::pixel: coordinate (172,540) out of range
          QImage::pixel: coordinate (173,540) out of range
          QImage::pixel: coordinate (174,540) out of range
          QImage::pixel: coordinate (175,540) out of range
          QImage::pixel: coordinate (168,541) out of range
          QImage::pixel: coordinate (169,541) out of range
          QImage::pixel: coordinate (170,541) out of range
          QImage::pixel: coordinate (171,541) out of range
          QImage::pixel: coordinate (172,541) out of range
          QImage::pixel: coordinate (173,541) out of range
          QImage::pixel: coordinate (174,541) out of range
          QImage::pixel: coordinate (175,541) out of range
          QImage::pixel: coordinate (168,542) out of range
          QImage::pixel: coordinate (169,542) out of range
          QImage::pixel: coordinate (170,542) out of range
          QImage::pixel: coordinate (171,542) out of range
          QImage::pixel: coordinate (172,542) out of range
          QImage::pixel: coordinate (173,542) out of range
          QImage::pixel: coordinate (174,542) out of range
          
          

          that's mean that my pix is null right?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 7 Jan 2017, 18:07 last edited by
          #133

          @Payx
          Yes this means that the pictures in the table cannot be loaded.
          Are they in a resource ?

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Payx
            wrote on 7 Jan 2017, 18:10 last edited by
            #134

            Yes i have that exactly :http://hpics.li/cc11b5c

            M 1 Reply Last reply 7 Jan 2017, 18:11
            0
            • P Payx
              7 Jan 2017, 18:10

              Yes i have that exactly :http://hpics.li/cc11b5c

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 7 Jan 2017, 18:11 last edited by mrjj 1 Jul 2017, 18:15
              #135

              @Payx
              Oh, they are under IMG

              Right click one image file.
              Find Get Path
              should be something like

              :/IMG/filename.xxx

              Fix the names in the table.
              As far as i recall they start like ":/filename.xxx" and that dont match.

              alt text

              Note: Here i do NOT have them in a sub folder like you have (img) so path is :/p1.png

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Payx
                wrote on 7 Jan 2017, 18:16 last edited by
                #136
                QMap<QRgb, CostInfo > Costs = {
                	{ QColor(255 , 0 , 0 ).rgb(), { ":/img/fraise.png", 10 }},
                	{ QColor(0 , 255 , 0 ).rgb(), { ":/img/balleverte.png", 20 }},	
                	{ QColor(0 , 0 , 255 ).rgb(), { ":/img/balebleue.png", 20 }},
                	{ QColor(255 , 255 , 255 ).rgb(), { ":/img/balleblanche.png", 20 }},
                	{ QColor(255 , 128 , 0 ).rgb(), { ":/img/ballepeche.png", 20 }},
                	{ QColor(0 , 0 , 0 ).rgb(), { ":/img/noir.png", 20 }},
                	{ QColor(102 , 51 , 0 ).rgb(), { ":/img/marron.png", 20 }},
                	{ QColor(255 , 102 , 78 ).rgb(), { ":/img/rose.png", 20 }},
                	{ QColor(0 , 204 , 204 ).rgb(), { ":/img/turquoise.png", 20 }},
                	{ QColor(255 , 178 , 102 ).rgb(), { ":/img/beige.png", 20 }},
                	{ QColor(76 , 0 , 153 ).rgb(), { ":/img/violet.png", 20 }},
                	{ QColor(100 , 100 , 100 ).rgb(), { ":/img/gris.png", 20 }},
                };
                
                

                i didnt mention that but i had already changed the path

                M 1 Reply Last reply 7 Jan 2017, 18:19
                0
                • P Payx
                  7 Jan 2017, 18:16
                  QMap<QRgb, CostInfo > Costs = {
                  	{ QColor(255 , 0 , 0 ).rgb(), { ":/img/fraise.png", 10 }},
                  	{ QColor(0 , 255 , 0 ).rgb(), { ":/img/balleverte.png", 20 }},	
                  	{ QColor(0 , 0 , 255 ).rgb(), { ":/img/balebleue.png", 20 }},
                  	{ QColor(255 , 255 , 255 ).rgb(), { ":/img/balleblanche.png", 20 }},
                  	{ QColor(255 , 128 , 0 ).rgb(), { ":/img/ballepeche.png", 20 }},
                  	{ QColor(0 , 0 , 0 ).rgb(), { ":/img/noir.png", 20 }},
                  	{ QColor(102 , 51 , 0 ).rgb(), { ":/img/marron.png", 20 }},
                  	{ QColor(255 , 102 , 78 ).rgb(), { ":/img/rose.png", 20 }},
                  	{ QColor(0 , 204 , 204 ).rgb(), { ":/img/turquoise.png", 20 }},
                  	{ QColor(255 , 178 , 102 ).rgb(), { ":/img/beige.png", 20 }},
                  	{ QColor(76 , 0 , 153 ).rgb(), { ":/img/violet.png", 20 }},
                  	{ QColor(100 , 100 , 100 ).rgb(), { ":/img/gris.png", 20 }},
                  };
                  
                  

                  i didnt mention that but i had already changed the path

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 7 Jan 2017, 18:19 last edited by mrjj 1 Jul 2017, 18:19
                  #137

                  @Payx
                  oh, it seems correct. You checked they are truly correct?

                  Please qDebug() << ci.ImageName to verify the variable contains the path from
                  the table.

                  just above where you try to make pixmap

                  qDebug() << "check me--->" << ci.ImageName;
                  QPixmap pix( ci.ImageName );

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Payx
                    wrote on 7 Jan 2017, 18:33 last edited by
                    #138

                    I have

                    check me---> ""
                    

                    so there is nothing

                    i declared as QString ImageName
                    so maybe it is that ?

                    M 1 Reply Last reply 7 Jan 2017, 18:34
                    0
                    • P Payx
                      7 Jan 2017, 18:33

                      I have

                      check me---> ""
                      

                      so there is nothing

                      i declared as QString ImageName
                      so maybe it is that ?

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 7 Jan 2017, 18:34 last edited by
                      #139

                      @Payx
                      Not sure. check the code that look it up.
                      If from table it should not be empty :)

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 7 Jan 2017, 18:35 last edited by
                        #140

                        Are you sure you are retrieving a valid value from your map ?

                        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
                        • P Offline
                          P Offline
                          Payx
                          wrote on 7 Jan 2017, 18:41 last edited by Payx 1 Jul 2017, 18:41
                          #141

                          No it's sure that it's not a valid value !

                          QPixmap pix( ci.ImageName );
                          

                          so it create a pix from a QString no ? that why it didnt work ?

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 7 Jan 2017, 18:52 last edited by
                            #142

                            From what you wrote before, ci.ImageName is empty, correct ?

                            If so, check the key that you use to retrieve the data from the map. If not part of the map, depending on the technique used, you will get a default constructed object.

                            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
                            • P Offline
                              P Offline
                              Payx
                              wrote on 7 Jan 2017, 19:15 last edited by
                              #143

                              Yes it's empty.

                              			foreach( QRgb key, Costs.keys() ) {
                              				QColor BaseColor( key );
                              				if (Costs.contains( colour.rgb() ) || IsCloseColor(BaseColor, colour) )  {
                              					CostInfo& ci = Costs[colour.rgb()];
                              					QLabel abc;
                              //          int Cost = ci.Cost;
                              					qDebug() << "check me--->" << ci.ImageName;
                              					QPixmap pix( ci.ImageName );
                              					if (pix.isNull()){
                              					qDebug() << "yep its no good";
                              					return;
                              					};
                              					QPixmap scaledPix = pix.scaled(   8, 8,
                              																				 Qt::KeepAspectRatio,
                              																				 Qt::SmoothTransformation
                              																				 );
                              					abc.setPixmap(scaledPix);
                              					abc.show();
                              

                              it's what i have.

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 7 Jan 2017, 21:07 last edited by
                                #144

                                Your logic is flawed. If Costs contains colour.rgb() then you can go on with the rest of your logic else you should go through your map and use IsCloseColor to determine which key is good. Then you can use that key to go further.

                                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
                                • P Offline
                                  P Offline
                                  Payx
                                  wrote on 7 Jan 2017, 21:47 last edited by
                                  #145

                                  So i have to separate the

                                  colour.rgb() ) || IsCloseColor(BaseColor, colour)
                                  

                                  ?

                                  can you tell me how can i got through my map i've already search and asked but no one answer

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 7 Jan 2017, 22:24 last edited by
                                    #146

                                    You're already doing it with your foreach loop and the documentation of QMap shows several ways of looping through its content.

                                    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
                                    • P Offline
                                      P Offline
                                      Payx
                                      wrote on 7 Jan 2017, 22:35 last edited by
                                      #147

                                      something like that ?

                                      			foreach( QRgb key, Costs.keys() ) {
                                      				QColor BaseColor( key );
                                      				if (Costs.contains( colour.rgb() ))  {
                                      					CostInfo& ci = Costs[colour.rgb()];
                                      					QLabel abc;
                                      //          int Cost = ci.Cost;
                                      					qDebug() << "check me--->" << ci.ImageName;
                                      					QPixmap pix( ci.ImageName );
                                      					if (pix.isNull()){
                                      					qDebug() << "yep its no good";
                                      					return;
                                      					};
                                      					QPixmap scaledPix = pix.scaled(   8, 8,
                                      																				 Qt::KeepAspectRatio,
                                      																				 Qt::SmoothTransformation
                                      																				 );
                                      					abc.setPixmap(scaledPix);
                                      					abc.show();
                                      
                                      				}
                                      				else {
                                      					if (IsCloseColor(BaseColor, colour) == true){
                                      						CostInfo& ci = Costs[colour.rgb()];
                                      						QColor BaseColor( key );
                                      						QPixmap pix( ci.ImageName );
                                      						QPixmap scaledPix = pix.scaled(   8, 8,
                                      																					 Qt::KeepAspectRatio,
                                      																					 Qt::SmoothTransformation
                                      																					 );
                                      						abc.setPixmap(scaledPix);
                                      						abc.show();
                                      					}
                                      					else {
                                      						qDebug() << "yep its no good";
                                      					}
                                      				}
                                      
                                      1 Reply Last reply
                                      0
                                      • S Offline
                                        S Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on 7 Jan 2017, 22:41 last edited by
                                        #148

                                        Move the foreach loop in the else part. There's no sense in looping through the whole map if it contains colour.rgb(). Also note that you won't see any QLabel since it's going out of scope.

                                        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
                                        • P Offline
                                          P Offline
                                          Payx
                                          wrote on 7 Jan 2017, 22:47 last edited by
                                          #149
                                          void Remplissage(QImage& image, const QPoint& topLeft, const QSize& rectangle, const QColor& colour) {
                                          
                                          	int maxX = topLeft.x() + rectangle.width();
                                          	int maxY = topLeft.y() + rectangle.height();
                                          
                                          	for(int x = topLeft.x(); x < maxX; ++x) {
                                          		for(int y = topLeft.y(); y < maxY; ++y) {
                                          			image.setPixelColor(x, y, colour);
                                          
                                          
                                          				QColor BaseColor( key );
                                          				if (Costs.contains( colour.rgb() ))  {
                                          					CostInfo& ci = Costs[colour.rgb()];
                                          					QLabel abc;
                                          //          int Cost = ci.Cost;
                                          					qDebug() << "check me--->" << ci.ImageName;
                                          					QPixmap pix( ci.ImageName );
                                          					if (pix.isNull()){
                                          					qDebug() << "yep its no good";
                                          					return;
                                          					};
                                          					QPixmap scaledPix = pix.scaled(   8, 8,
                                          																				 Qt::KeepAspectRatio,
                                          																				 Qt::SmoothTransformation
                                          																				 );
                                          					abc.setPixmap(scaledPix);
                                          					abc.show();
                                          
                                          				}
                                          				else {
                                          					if (IsCloseColor(BaseColor, colour) == true){
                                          						foreach( QRgb key, Costs.keys() ) {
                                          						CostInfo& ci = Costs[colour.rgb()];
                                          						QLabel abc;
                                          						QColor BaseColor( key );
                                          						QPixmap pix( ci.ImageName );
                                          						QPixmap scaledPix = pix.scaled(   8, 8,
                                          																					 Qt::KeepAspectRatio,
                                          																					 Qt::SmoothTransformation
                                          																					 );
                                          						abc.setPixmap(scaledPix);
                                          						abc.show();
                                          					}
                                          					else {
                                          						qDebug() << "yep its no good";
                                          					}
                                          				}
                                          
                                          

                                          i changed what u said

                                          1 Reply Last reply
                                          0

                                          139/196

                                          7 Jan 2017, 18:34

                                          • Login

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