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

How to include .txt on Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
196 Posts 11 Posters 134.9k 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 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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 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
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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 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
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #150

                  I'd guess it doesn't compile.

                  Your BaseColor variable doesn't make sense where it's declared. The if (IsCloseColor... also doesn't make sense where you put it. You are searching the map to find which of its key is close to the colour you received. But currently if BaseColor fits you are just trying to show each and every element of Costs.

                  Again: your QLable objects will be destroyed before they are even shown.

                  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 last edited by Payx
                    #151

                    Yes but i dont want to display one picture so the label is here just for display the picture from my QMap my final picture with all the QMap's image is display in the label_3

                    sorry but i loose you ^^

                    the if (IsClose .. doesnt make sense ? i put it after the else because if the bool dont return true we can't continue no?

                    ""BaseColor fits you are just trying to show each and every element of Costs.""
                    so maybe replace "foreach( QRgb key, Costs.keys() )" by just "foreach(only the image)" can i write ImageName.key ?

                    FlotisableF 1 Reply Last reply
                    0
                    • P Payx

                      Yes but i dont want to display one picture so the label is here just for display the picture from my QMap my final picture with all the QMap's image is display in the label_3

                      sorry but i loose you ^^

                      the if (IsClose .. doesnt make sense ? i put it after the else because if the bool dont return true we can't continue no?

                      ""BaseColor fits you are just trying to show each and every element of Costs.""
                      so maybe replace "foreach( QRgb key, Costs.keys() )" by just "foreach(only the image)" can i write ImageName.key ?

                      FlotisableF Offline
                      FlotisableF Offline
                      Flotisable
                      wrote on last edited by Flotisable
                      #152

                      @Payx
                      I think what @SGaist says is that

                      if Costs contains colour.rgb() you can do what you want
                      else you should go though the Costs to search if there is a BaseColor that is close to colour
                      and if there is one, you can do what you want

                      what you do now is
                      if Costs contains colour.rgb() you do what you want
                      else test if BaseColor is close to colour
                      if it is then you go though the Costs and do what you want

                      the difference is that
                      you are not search for a BaseColor that is close to colour( which is a foreach then if )
                      but test if BaseColor is close to colour and go though the Costs( which is a if then foreach )
                      and the BaseColor is unknown since there is no key defined before it

                      1 Reply Last reply
                      1
                      • P Offline
                        P Offline
                        Payx
                        wrote on last edited by Payx
                        #153
                        				else {
                        					if (IsCloseColor(BaseColor, colour) == true){
                        						foreach( QRgb key, Costs.keys() ) {
                        

                        its what i did no ?

                        EDIT : it tell me that key isnt declared in QColor BaseColor( key );

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

                          No, what you are doing is that if colour is close to base colour you loop on your map.

                          What you want to do is loop on the map and if any of the colour ÌsCloseColour` then use that one.

                          As for the build error, look where you declared key and where you are currently using it.

                          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 last edited by
                            #155

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

                            What you want to do is loop on the map and if any of the colour ÌsCloseColour` then use that one.

                            Sorry if i don't understand well but """IsCloseColor(BaseColor, colour) == true""" dont mean that if any of the color IsCloreColour ?

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

                              No, that function checks the whether the colours passed as parameters are close.

                              What you want to do is check which one of the map entries is close to the reference.

                              Take a look at your code and the order in which you wrote it. You are not testing the content of the Costs map, you are just checking whether colour is close to BaseColor which currently you can't create since your key variable is inside your loop and not outside where you declared BaseColor.

                              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 last edited by
                                #157

                                Ok,

                                					foreach( QRgb key, Costs.keys() ) {
                                					QColor BaseColor( key );
                                					if (IsCloseColor(BaseColor, colour) == true){
                                

                                so first i loop on my map, i declare my BaseColor who is the color in my map, and i check if it's close to my color's reference, right ?

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

                                  Looks better, yes.

                                  Don't forget to break out of the loop once you found a match.

                                  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 last edited by Payx
                                    #159

                                    so it compile but i got the 3 same errors :

                                    QPixmap::scaled: Pixmap is a null pixmap
                                    
                                    setGeometry: Unable to set geometry 5x13+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x13+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                                    
                                    yep its no good
                                    
                                    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);
                                    
                                    
                                    
                                    
                                    				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 {
                                    					foreach( QRgb key, Costs.keys() ) {
                                    					QColor BaseColor( key );
                                    					if (IsCloseColor(BaseColor, colour) == true){
                                    
                                    						CostInfo& ci = Costs[colour.rgb()];
                                    						QLabel abc;
                                    						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 put my code here

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

                                      Because you are still trying to get the wrong entry from your map. If you enter your foreach loop, it means that colour can't be found in your map thus you can't use it to get the value from the map.

                                      IsCloseColor tells you that BaseColor and colour are close, then you must use key to get the CostInfo you want.

                                      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 last edited by Payx
                                        #161

                                        Ok i understand, so it doesnt work because i still search my color in my map.

                                        So i have to replace color by basecolor (when IsCloseColor(BaseColor, colour) == true) right ? and search for basecolor in my map ?

                                        FlotisableF 1 Reply Last reply
                                        0
                                        • P Payx

                                          Ok i understand, so it doesnt work because i still search my color in my map.

                                          So i have to replace color by basecolor (when IsCloseColor(BaseColor, colour) == true) right ? and search for basecolor in my map ?

                                          FlotisableF Offline
                                          FlotisableF Offline
                                          Flotisable
                                          wrote on last edited by
                                          #162

                                          @Payx
                                          yes

                                          1 Reply Last reply
                                          0

                                          • Login

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