How to increment Image name ?
-
@hamzaelazizi said in How to increment Image name ?:
i've tried multiple approaches but none of them worked! :(
I don't know how you are generating the ID, if it is a free running counter why not use the modulo function?
QString fileName = QString("%1.png").arg(1 + (id % 11));@KroMignon I wanted to use it, in fact i was trying it over and over but since i'm new to Qt i didn't know how to get it to work :( (i feel ashamed now), when i tried your solution, it seems like it's working! i don't know if i will be running into some issues in the futur, but i guess that would be a problem for another day, Thank you
-
@jsulm said in How to increment Image name ?:
The id is comming from https://doc.qt.io/qt-5/qcameraimagecapture.html#imageCaptured
I see! :D
So this would also not work!
Then I don't see another solution as what @jsulm already suggested: use class member to store the counter value@KroMignon said in How to increment Image name ?:
So this would also not work!
Actually it should :-)
-
@KroMignon said in How to increment Image name ?:
So this would also not work!
Actually it should :-)
@jsulm said in How to increment Image name ?:
Actually it should :-)
Okay, I never used
QCameraImageCapture, so I supposed the ID would be the ID of the used camera and not if the image...
Maybe I should avoid the reply to posts for topics I not experimented in! -
@jsulm said in How to increment Image name ?:
Actually it should :-)
Okay, I never used
QCameraImageCapture, so I supposed the ID would be the ID of the used camera and not if the image...
Maybe I should avoid the reply to posts for topics I not experimented in!@KroMignon Sir, your solution helped me, so i think you should keep relying to this kind of posts :D, i have one last question, @jsulm how can i use my own id variable ? should i create a variable inside this class ? i don't understand !
-
@KroMignon Sir, your solution helped me, so i think you should keep relying to this kind of posts :D, i have one last question, @jsulm how can i use my own id variable ? should i create a variable inside this class ? i don't understand !
@hamzaelazizi said in How to increment Image name ?:
should i create a variable inside this class ?
Yes and you initialize it with 0. Each time your slot is called you increment it and check whether it is bigger than the max id value you want to use, if it is you set it back to 0.
-
@hamzaelazizi said in How to increment Image name ?:
should i create a variable inside this class ?
Yes and you initialize it with 0. Each time your slot is called you increment it and check whether it is bigger than the max id value you want to use, if it is you set it back to 0.
@jsulm something like this ?
QObject::connect(_image_capture.data(), &QCameraImageCapture::imageCaptured, [=] (int id=0, QImage img) { int idx = 0; if(idx>=11) { idx=0; } else { idx++; } QString fileName = QString::number(idx) + ".png"; QString path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/" + fileName; img.save(path, "PNG"); });Because i've tried this and it didn't work :/
-
@jsulm something like this ?
QObject::connect(_image_capture.data(), &QCameraImageCapture::imageCaptured, [=] (int id=0, QImage img) { int idx = 0; if(idx>=11) { idx=0; } else { idx++; } QString fileName = QString::number(idx) + ".png"; QString path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/" + fileName; img.save(path, "PNG"); });Because i've tried this and it didn't work :/
@hamzaelazizi said in How to increment Image name ?:
something like this ?
No.
In your code idx is a local variable and not a class member... -
@jsulm something like this ?
QObject::connect(_image_capture.data(), &QCameraImageCapture::imageCaptured, [=] (int id=0, QImage img) { int idx = 0; if(idx>=11) { idx=0; } else { idx++; } QString fileName = QString::number(idx) + ".png"; QString path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/" + fileName; img.save(path, "PNG"); });Because i've tried this and it didn't work :/
I have updated my previous post. Please, try it again.
-
@hamzaelazizi said in How to increment Image name ?:
something like this ?
No.
In your code idx is a local variable and not a class member...@jsulm i see, but whenever i declare a variable outside the method i get this error saying that the variable i created is a Read-only
-
@jsulm i see, but whenever i declare a variable outside the method i get this error saying that the variable i created is a Read-only
@hamzaelazizi Depends what you write and where.
-
@jsulm i see, but whenever i declare a variable outside the method i get this error saying that the variable i created is a Read-only
@hamzaelazizi said in How to increment Image name ?:
outside the method
I never suggested to declare it outside of the method. I suggested to declare it as a class member:
class YOUR_CLASS: { private: int idx{0}; -
@hamzaelazizi said in How to increment Image name ?:
outside the method
I never suggested to declare it outside of the method. I suggested to declare it as a class member:
class YOUR_CLASS: { private: int idx{0};@jsulm i understand now, thank you for your explanation