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.9k 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 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
    • M Offline
      M 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
      • M 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
        • P Offline
          P Offline
          Payx
          wrote on 9 Jan 2017, 14:26 last edited by
          #170
          its OK with base color
          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).
          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
          its OK with base color
          

          So no problem about BaseColor !

          F 1 Reply Last reply 9 Jan 2017, 14:37
          1
          • P Payx
            9 Jan 2017, 14:26
            its OK with base color
            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).
            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
            its OK with base color
            

            So no problem about BaseColor !

            F Offline
            F Offline
            Flotisable
            wrote on 9 Jan 2017, 14:37 last edited by
            #171

            @Payx
            I think you can output the imageName in the foreach to check if there is a file name.

            and you can try to use debug mode and execute step by step to find out which line cause the problem.

            maybe it will be more clear what's wrong with it.

            1 Reply Last reply
            1
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 9 Jan 2017, 14:39 last edited by mrjj 1 Sept 2017, 14:39
              #172

              Hi
              Yes as @Flotisable says, you should check what is going on with the file name

              so

              xxxx
              QPixmap pix( ci.ImageName );
              qDebug() << "image i get from ci.ImageName : " << ci.ImageName;

              and see what it really is.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Payx
                wrote on 9 Jan 2017, 14:44 last edited by Payx 1 Sept 2017, 14:45
                #173

                with qDebug() << "image i get from ci.ImageName : " << ci.ImageName;

                image i get from ci.ImageName :  ":/img/noir.png"
                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).
                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
                its OK with base color
                image i get from ci.ImageName :  ":/img/noir.png"
                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).
                yep its no good
                
                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 9 Jan 2017, 14:50 last edited by
                  #174

                  Ok so path is good ? seems ok.
                  So I guess it does load it there. ( in pix)
                  But why does

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

                  still trigger then ?

                  or is that from
                  if (IsCloseColor(BaseColor, colour) == true){
                  xxx
                  }
                  else {
                  qDebug() << "yep its no good";
                  }

                  ?

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Payx
                    wrote on 9 Jan 2017, 14:52 last edited by Payx 1 Sept 2017, 15:05
                    #175

                    EDIT :

                    i replaced this line "diffBlue + diffRed + diffGreen < 100" 100 by 450 and increase the picture to a 20 * 20

                    i have :

                    image i get from ci.ImageName :  ":/img/fraise.png"
                    setGeometry: Unable to set geometry 20x16+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x16+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/rose.png"
                    setGeometry: Unable to set geometry 20x14+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x14+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/ballepeche.png"
                    setGeometry: Unable to set geometry 19x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    yep its no good
                    yep its no good
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/noir.png"
                    setGeometry: Unable to set geometry 20x17+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x17+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/balebleue.png"
                    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).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/turquoise.png"
                    setGeometry: Unable to set geometry 11x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/balleverte.png"
                    setGeometry: Unable to set geometry 20x15+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x15+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/violet.png"
                    setGeometry: Unable to set geometry 15x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/gris.png"
                    setGeometry: Unable to set geometry 16x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/marron.png"
                    setGeometry: Unable to set geometry 8x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/fraise.png"
                    setGeometry: Unable to set geometry 20x16+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x16+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/rose.png"
                    setGeometry: Unable to set geometry 20x14+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x14+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/ballepeche.png"
                    setGeometry: Unable to set geometry 19x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                    yep its no good
                    yep its no good
                    its OK with base color
                    image i get from ci.ImageName :  ":/img/noir.png"
                    

                    its better no ?

                    and i had already changed into a

                    					if (pix.isNull()){
                    					qDebug() << "nothing";
                    					return;
                    					};
                    

                    to see exactly where it bug

                    EDIT : it will not be displayed on my label, so if i put my the definition of my label in my .h doest it work?

                    M 1 Reply Last reply 9 Jan 2017, 15:11
                    0
                    • P Payx
                      9 Jan 2017, 14:52

                      EDIT :

                      i replaced this line "diffBlue + diffRed + diffGreen < 100" 100 by 450 and increase the picture to a 20 * 20

                      i have :

                      image i get from ci.ImageName :  ":/img/fraise.png"
                      setGeometry: Unable to set geometry 20x16+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x16+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/rose.png"
                      setGeometry: Unable to set geometry 20x14+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x14+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/ballepeche.png"
                      setGeometry: Unable to set geometry 19x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      yep its no good
                      yep its no good
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/noir.png"
                      setGeometry: Unable to set geometry 20x17+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x17+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/balebleue.png"
                      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).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/turquoise.png"
                      setGeometry: Unable to set geometry 11x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/balleverte.png"
                      setGeometry: Unable to set geometry 20x15+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x15+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/violet.png"
                      setGeometry: Unable to set geometry 15x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/gris.png"
                      setGeometry: Unable to set geometry 16x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/marron.png"
                      setGeometry: Unable to set geometry 8x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/fraise.png"
                      setGeometry: Unable to set geometry 20x16+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x16+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/rose.png"
                      setGeometry: Unable to set geometry 20x14+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x14+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/ballepeche.png"
                      setGeometry: Unable to set geometry 19x20+640+280 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry:  120x20+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
                      yep its no good
                      yep its no good
                      its OK with base color
                      image i get from ci.ImageName :  ":/img/noir.png"
                      

                      its better no ?

                      and i had already changed into a

                      					if (pix.isNull()){
                      					qDebug() << "nothing";
                      					return;
                      					};
                      

                      to see exactly where it bug

                      EDIT : it will not be displayed on my label, so if i put my the definition of my label in my .h doest it work?

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 9 Jan 2017, 15:11 last edited by
                      #176

                      @Payx
                      Well it seems you just do
                      QLabel abc;
                      which will not work at all as this label is then deleted as soon as function ends.

                      Putting it in .h will help it not getting deleted but its still not connected to the screen in any way.
                      If you have UI file. Cant u put it there?
                      and get via
                      ui->label
                      Then its in the right place.

                      To do this, you must make Remplissage member of the mainwindow so you can acces its UI

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        Payx
                        wrote on 9 Jan 2017, 15:41 last edited by
                        #177

                        Yes but if i create a label in my UI the picture will just be displayed in the same label no ?

                        M 1 Reply Last reply 9 Jan 2017, 16:07
                        0
                        • P Payx
                          9 Jan 2017, 15:41

                          Yes but if i create a label in my UI the picture will just be displayed in the same label no ?

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 9 Jan 2017, 16:07 last edited by
                          #178

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

                          a label in my UI the picture will just be displayed in the same label no ?

                          Yes. You can add more than one label if u need more pics to be shown at same time.

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            Payx
                            wrote on 9 Jan 2017, 16:28 last edited by
                            #179

                            my funtion is

                            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) {
                            

                            in

                            Remplissage(pixi, QPoint(i, j), QSize(z, z), Couleurdominante(pixi, QPoint(i, j), QSize(z, z)));
                            

                            so it depends on my z, if i say that my z = 20; and if my picture is 540 * 540 i will need 729 labels lol.

                            example :

                            here my previous code : http://hpics.li/36d1f82

                            my picture is 128 * 128, if my z = 28; it appears 4 colors by 4 colors.

                            How can i display a picture by color without add 10000 labels, thats why i though that create a label in my loop will work

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 9 Jan 2017, 21:40 last edited by
                              #180

                              Create a new image and put it into a secondary QLabel.

                              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 9 Jan 2017, 22:50 last edited by Payx 1 Oct 2017, 09:56
                                #181

                                Something like :
                                QImage from pix
                                And put the image into a label ?

                                I know that put a label into a loop wont work u told me. But how can i do so ?

                                1 Reply Last reply
                                0
                                • P Offline
                                  P Offline
                                  Payx
                                  wrote on 10 Jan 2017, 16:21 last edited by Payx 1 Oct 2017, 16:24
                                  #182

                                  nobody know how to ?

                                  or maybe an other way, if its too complicated ^^

                                  M 1 Reply Last reply 10 Jan 2017, 16:50
                                  0
                                  • P Payx
                                    10 Jan 2017, 16:21

                                    nobody know how to ?

                                    or maybe an other way, if its too complicated ^^

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 10 Jan 2017, 16:50 last edited by
                                    #183

                                    @Payx
                                    You lost me on what you are trying with the Labels. 729 ?!?!
                                    Do you mean to have the lables like
                                    alt text
                                    or how would you place all these labels?

                                    1 Reply Last reply
                                    0
                                    • P Offline
                                      P Offline
                                      Payx
                                      wrote on 10 Jan 2017, 16:55 last edited by
                                      #184

                                      label is not obligatory, it's just me with my few knowlegde that i said i can use labels.

                                      but the problem is that i have to replace the color by the picture (replace or add) and its here that i'm blocked

                                      M 1 Reply Last reply 10 Jan 2017, 16:56
                                      0
                                      • P Payx
                                        10 Jan 2017, 16:55

                                        label is not obligatory, it's just me with my few knowlegde that i said i can use labels.

                                        but the problem is that i have to replace the color by the picture (replace or add) and its here that i'm blocked

                                        M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 10 Jan 2017, 16:56 last edited by mrjj 1 Oct 2017, 16:57
                                        #185

                                        @Payx
                                        on top of the "red" image ? so that each cell is an image?

                                        1 Reply Last reply
                                        1
                                        • P Offline
                                          P Offline
                                          Payx
                                          wrote on 10 Jan 2017, 17:01 last edited by Payx 1 Nov 2017, 01:02
                                          #186

                                          yes each cell is an image.

                                          on the picture that you showed there is 16 cell so 16 picture who depend on the color

                                          Edit : we had before "image.setPixelColor(x, y, colour);"

                                          can't we have like image.'setImage' or something?

                                          F 1 Reply Last reply 11 Jan 2017, 02:03
                                          0

                                          176/196

                                          9 Jan 2017, 15:11

                                          • Login

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