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 142.4k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 7 Jan 2017, 23:04 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 7 Jan 2017, 23:20 last edited by Payx 1 Jul 2017, 23:21
      #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 ?

      F 1 Reply Last reply 8 Jan 2017, 03:39
      0
      • P Payx
        7 Jan 2017, 23:20

        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 ?

        F Offline
        F Offline
        Flotisable
        wrote on 8 Jan 2017, 03:39 last edited by Flotisable 1 Aug 2017, 03:44
        #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 8 Jan 2017, 13:06 last edited by Payx 1 Aug 2017, 14:36
          #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
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 8 Jan 2017, 20:52 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 8 Jan 2017, 21:41 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
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 8 Jan 2017, 21:50 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 8 Jan 2017, 22:11 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
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 8 Jan 2017, 22:13 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 8 Jan 2017, 22:21 last edited by Payx 1 Aug 2017, 22:21
                      #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
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 8 Jan 2017, 22:53 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 8 Jan 2017, 23:22 last edited by Payx 1 Aug 2017, 23:23
                          #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 ?

                          F 1 Reply Last reply 8 Jan 2017, 23:38
                          0
                          • P Payx
                            8 Jan 2017, 23:22

                            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 ?

                            F Offline
                            F Offline
                            Flotisable
                            wrote on 8 Jan 2017, 23:38 last edited by
                            #162

                            @Payx
                            yes

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              Payx
                              wrote on 8 Jan 2017, 23:43 last edited by
                              #163

                              am i right if i write

                              CostInfo& ci = Costs[BaseColor.rgb()];
                              

                              ?

                              1 Reply Last reply
                              0
                              • F Offline
                                F Offline
                                Flotisable
                                wrote on 8 Jan 2017, 23:48 last edited by
                                #164

                                yes

                                by the way, you don't need to write if( IsCloseColor( BaseColor , colour ) == true ) explicitly. Yout can write if( IsColseColor( BaseColor , colour ) ) since the return value of IsCloseColor is already a bool and if can test it

                                1 Reply Last reply
                                0
                                • P Offline
                                  P Offline
                                  Payx
                                  wrote on 8 Jan 2017, 23:51 last edited by
                                  #165

                                  Ok so it compile,

                                  but i have the same error again :

                                  yep its no good
                                  yep its no good
                                  yep its no good
                                  setGeometry: Unable to set geometry 8x7+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x7+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                                  

                                  *1000

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 9 Jan 2017, 10:23 last edited by
                                    #166

                                    Again checkout what you get, whether what it contains is valid.

                                    And again 2, you are creating QLabels that will be destroyed before they can be shown.

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

                                    P 1 Reply Last reply 9 Jan 2017, 13:41
                                    0
                                    • S SGaist
                                      9 Jan 2017, 10:23

                                      Again checkout what you get, whether what it contains is valid.

                                      And again 2, you are creating QLabels that will be destroyed before they can be shown.

                                      P Offline
                                      P Offline
                                      Payx
                                      wrote on 9 Jan 2017, 13:41 last edited by Payx 1 Sept 2017, 13:46
                                      #167

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

                                      And again 2, you are creating QLabels that will be destroyed before they can be shown.

                                      So maybe write "QLabel abc;" in my .h ?

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

                                      Again checkout what you get, whether what it contains is valid.

                                      i have

                                      						CostInfo& ci = Costs[BaseColor.rgb()];
                                      						QPixmap pix( ci.ImageName );
                                      

                                      Maybe i don't understand well this 2 lines, i explain what i understand and tell me if i'm wrong.

                                      The first line put in my variable ci the "line" referent to my BaseColor ( it stock the Costs (who have a QString and a Int))

                                      the second line create a pixmap from the ImageName referent to my BaseColor. So something like (QPixmap pix(:/img/ballepeche.png))

                                      1 Reply Last reply
                                      0
                                      • mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 9 Jan 2017, 14:05 last edited by mrjj 1 Sept 2017, 14:06
                                        #168

                                        Hi
                                        Make sure that
                                        BaseColor.rgb() actually give a 100% MATCH else u insert empty one with no file name and ImageName will be empty!

                                        I think u are using it wrongly.

                                        try
                                        if ( Costs.contains( BaseColor.rgb()))
                                        qDebug () << "its OK with base color";
                                        else
                                        qDebug () << " base color had no match!!"

                                        before
                                        CostInfo& ci = Costs[BaseColor.rgb()];
                                        QPixmap pix( ci.ImageName );

                                        As if base color is NOT 1 of the colors in qmpa, it dont work and image is empty.

                                        F 1 Reply Last reply 9 Jan 2017, 14:11
                                        0
                                        • mrjjM mrjj
                                          9 Jan 2017, 14:05

                                          Hi
                                          Make sure that
                                          BaseColor.rgb() actually give a 100% MATCH else u insert empty one with no file name and ImageName will be empty!

                                          I think u are using it wrongly.

                                          try
                                          if ( Costs.contains( BaseColor.rgb()))
                                          qDebug () << "its OK with base color";
                                          else
                                          qDebug () << " base color had no match!!"

                                          before
                                          CostInfo& ci = Costs[BaseColor.rgb()];
                                          QPixmap pix( ci.ImageName );

                                          As if base color is NOT 1 of the colors in qmpa, it dont work and image is empty.

                                          F Offline
                                          F Offline
                                          Flotisable
                                          wrote on 9 Jan 2017, 14:11 last edited by
                                          #169

                                          @mrjj
                                          @Payx's BaseColor is constructed from the key of Costs, so I think there is no problem

                                          1 Reply Last reply
                                          1

                                          159/196

                                          8 Jan 2017, 22:21

                                          • Login

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