How to include .txt on Qt
-
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?
@Payx
Yes this means that the pictures in the table cannot be loaded.
Are they in a resource ? -
wrote on 7 Jan 2017, 18:10 last edited by
Yes i have that exactly :http://hpics.li/cc11b5c
-
Yes i have that exactly :http://hpics.li/cc11b5c
Lifetime Qt Championwrote on 7 Jan 2017, 18:11 last edited by mrjj 1 Jul 2017, 18:15@Payx
Oh, they are under IMGRight 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.Note: Here i do NOT have them in a sub folder like you have (img) so path is :/p1.png
-
wrote on 7 Jan 2017, 18:16 last edited by
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
-
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
Lifetime Qt Championwrote on 7 Jan 2017, 18:19 last edited by mrjj 1 Jul 2017, 18:19@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 ); -
wrote on 7 Jan 2017, 18:33 last edited by
I have
check me---> ""
so there is nothing
i declared as QString ImageName
so maybe it is that ? -
I have
check me---> ""
so there is nothing
i declared as QString ImageName
so maybe it is that ?@Payx
Not sure. check the code that look it up.
If from table it should not be empty :) -
Are you sure you are retrieving a valid value from your map ?
-
wrote on 7 Jan 2017, 18:41 last edited by Payx 1 Jul 2017, 18:41
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 ?
-
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.
-
wrote on 7 Jan 2017, 19:15 last edited by
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.
-
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 useIsCloseColor
to determine which key is good. Then you can use that key to go further. -
wrote on 7 Jan 2017, 21:47 last edited by
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
-
You're already doing it with your foreach loop and the documentation of QMap shows several ways of looping through its content.
-
wrote on 7 Jan 2017, 22:35 last edited by
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"; } }
-
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. -
wrote on 7 Jan 2017, 22:47 last edited by
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
-
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 ofCosts
.Again: your QLable objects will be destroyed before they are even shown.
-
wrote on 7 Jan 2017, 23:20 last edited by Payx 1 Jul 2017, 23:21
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 ? -
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 ?wrote on 8 Jan 2017, 03:39 last edited by Flotisable 1 Aug 2017, 03:44@Payx
I think what @SGaist says is thatif
Costs
containscolour.rgb()
you can do what you want
else you should go though theCosts
to search if there is aBaseColor
that is close tocolour
and if there is one, you can do what you wantwhat you do now is
ifCosts
containscolour.rgb()
you do what you want
else test ifBaseColor
is close tocolour
if it is then you go though theCosts
and do what you wantthe difference is that
you are not search for aBaseColor
that is close tocolour
( which is aforeach
thenif
)
but test ifBaseColor
is close tocolour
and go though theCosts
( which is aif
thenforeach
)
and theBaseColor
is unknown since there is nokey
defined before it
142/196