How to include .txt on Qt
-
@ambershark Lol
I prefer learn instead of just don't understand what i'm doing, i know i'm very bad to programmation by now but maybe in few years i'il be like mrjj haha !
for the QPoint, i use it here :
void MainWindow::on_push2_clicked() { for (int i=0;i<pixi.width();i+=z){ for (int j=0;j<pixi.height();j+=z){ k=k+0.06; Remplissage(pixi,QPoint(i,j),QSize(z,z),Couleurdominante(pixi,QPoint(i,j),QSize(z,z))); } }
but i use the QPixmap scaledPix .....
in my functionvoid Remplissage(QImage& image, const QPoint& topLeft, const QSize& rectangle, const QColor& colour) {
so it tell that j and i was not declared in this scope
so i declared i and j in my .h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QPixmap> #include <QPoint> #include <QSize> #include <iostream> #include <QMapIterator> #include <QMap> namespace Ui { class MainWindow; } struct CostInfo { QString ImageName; int Cost; }; int j; int i; class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget* parent = 0); ~MainWindow(); private slots: void on_push_clicked(); void on_push2_clicked(); void on_verticalSlider_sliderMoved(int position); private: Ui::MainWindow* ui; QImage pixi; QPixmap pixa; float k; int a; int z = 1; int b; }; #endif // MAINWINDOW_HH
it will work?
//
it tell that painter was not declared too, so i search to the QPainter class,
it's "void QPainter::drawPixmap(const QPoint & point, const QPixmap & pixmap)" that i should use ?
wrote on 2 Jan 2017, 00:49 last edited by@Payx said in How to include .txt on Qt:
@ambershark Lol
I prefer learn instead of just don't understand what i'm doing, i know i'm very bad to programmation by now but maybe in few years i'il be like mrjj haha !
Haha it's good that you are learning instead of asking for it done like a lot of people on these forums. And hey we all started out bad, don't worry you'll be good in no time if you stick with it. ;)
I was just quite impressed with the number of posts in this topic.
-
@Payx said in How to include .txt on Qt:
@ambershark Lol
I prefer learn instead of just don't understand what i'm doing, i know i'm very bad to programmation by now but maybe in few years i'il be like mrjj haha !
Haha it's good that you are learning instead of asking for it done like a lot of people on these forums. And hey we all started out bad, don't worry you'll be good in no time if you stick with it. ;)
I was just quite impressed with the number of posts in this topic.
wrote on 2 Jan 2017, 14:09 last edited by@ambershark No problem ^^!
-
wrote on 5 Jan 2017, 15:15 last edited by Payx 1 Jul 2017, 00:03This post is deleted!
-
wrote on 7 Jan 2017, 00:04 last edited by
I tried something without you (sorry ahah)
QLabel abc; abc.setPixmap(scaledPix); abc.show();
it compiles but there is a error : QPixmap::scaled: Pixmap is a null pixmap
-
I tried something without you (sorry ahah)
QLabel abc; abc.setPixmap(scaledPix); abc.show();
it compiles but there is a error : QPixmap::scaled: Pixmap is a null pixmap
Lifetime Qt Championwrote on 7 Jan 2017, 01:32 last edited by mrjj 1 Jul 2017, 01:32@Payx said in How to include .txt on Qt:
scaledPix
Sounds like scaledPix is not initialize as it should , which often
comes from not being able to load a file.Make sure the image you are scaling, is indeed valid. (loaded)
-
wrote on 7 Jan 2017, 01:51 last edited by Payx 1 Jul 2017, 02:09
Before posting, i've tried to just
QPixmap pix(":/img/ballebleue.png") ui->setPixmap .....
and it works
u said "scaledPix is not initialize as it should ?"
EDIT : Happy New Year !
-
Before posting, i've tried to just
QPixmap pix(":/img/ballebleue.png") ui->setPixmap .....
and it works
u said "scaledPix is not initialize as it should ?"
EDIT : Happy New Year !
Yes That would make the pix valid.
To get the error " Pixmap is a null pixmap" for scaledPix means that
it was not valid. It was empty. so if it came from a scale function, it means
that the image u scaled to get scaledPix was empty.Happy new Year :)
-
wrote on 7 Jan 2017, 16:51 last edited by
QLabel abc; // int Cost = ci.Cost; QPixmap pix( ci.ImageName ); QPixmap scaledPix = pix.scaled( 8, 8, Qt::KeepAspectRatio, Qt::SmoothTransformation ); abc.setPixmap(scaledPix); abc.show();
i have this :
so the error come from "QPixmap pix" who is empty
so the line "QPixmap pix( ci.ImageName );" dont create a pixmap from my QMap ?
-
- QPixmap pix( ci.ImageName );" dont create a pixmap from my QMap ?
That would be my guess yes.
You can check pix with isNull()
-
wrote on 7 Jan 2017, 17:56 last edited by
So i add the if :
if (pix.isNull()){ QPixmap pix(":/img/ballebleue.png"); };
Same error as before "QPixmap::scaled: Pixmap is a null pixmap"
-
So i add the if :
if (pix.isNull()){ QPixmap pix(":/img/ballebleue.png"); };
Same error as before "QPixmap::scaled: Pixmap is a null pixmap"
@Payx said in How to include .txt on Qt:
if (pix.isNull()){
QPixmap pix(":/img/ballebleue.png");
};Well that would not really change anything as you create a new local pix and its not related to the "pix" outside
You should find out if its invalid and then why it isif (pix.isNull()){
qDebug() << "yep its no good";
return;
}; -
wrote on 7 Jan 2017, 18:06 last edited by
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?
-
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 ?
121/196