How to include .txt on Qt
-
-
Looks better, yes.
Don't forget to break out of the loop once you found a match.
-
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
-
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 thatBaseColor
andcolour
are close, then you must usekey
to get the CostInfo you want. -
yes
by the way, you don't need to write
if( IsCloseColor( BaseColor , colour ) == true )
explicitly. Yout can writeif( IsColseColor( BaseColor , colour ) )
since the return value ofIsCloseColor
is already abool
andif
can test it -
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
-
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.
-
@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))
-
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.
-
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 !
-
@Payx
I think you can output theimageName
in theforeach
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.
-
Hi
Yes as @Flotisable says, you should check what is going on with the file nameso
xxxx
QPixmap pix( ci.ImageName );
qDebug() << "image i get from ci.ImageName : " << ci.ImageName;and see what it really is.
-
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
-
Ok so path is good ? seems ok.
So I guess it does load it there. ( in pix)
But why doesif (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";
}?
-
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?
-
@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