Problem with Qlist and QMessangeLogger
-
I was making a simple program to convert text to pixels and save them as a png file. Everything was working as expected until I've changed one of my variables from array to QList.
When I try to compile this code, I get two errors, one of them is in my own code and it says :
F:\GraphicalCrypter\GraphicalCrypter\encryptmy.cpp:46: błąd: cannot convert 'QList<int>' to 'int' for argument '1' to 'constexpr QRgb qRgba(int, int, int, int)' value = qRgba(intArray[index-3], intArray[index-2], intArray[index-1],intArray[index]);
and the second one is in qlogging.h, which, as far as I know is one of the Qts files.
C:\Qt\Qt5.7.0\5.7\mingw53_32\include\QtCore\qlogging.h:158: błąd: expected ',' or ';' before 'QMessageLogger' #define qDebug QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug
Here is my code:
//encryptmy.cpp
http://pastebin.com/Wvi24uRW//encryptmy.hpp
http://pastebin.com/MZsTpAyQ//main.cpp
http://pastebin.com/KD2ASULwThose errors are appearing in lines : 46 (encryptmy.cpp) and 158 (qlogging,hpp)
I can't understand why is he giving me those errors.
Thanks in advance!
-
You've got a lot of indexing problems there.
I think you intended to create a list of ints but this
QList <int> intArray[texxt.length()];
is not a list of ints. It's an array of lists of ints i.e. it's a 2-dimentional structure. It should be calledarrayOfListsOfInts
notintArray
.If you really wanted an array of lists, then the following code has an "off by 1" error in it:
for (int d=0; d <texxt.size();d++) { ... intArray[d+1].append(test.toLatin1());
For last d this accesses an element beyond the end of the array.
The problem in line 46:
qRgba(intArray[index-3], ...
is thatqRgba
is expecting numbers as arguments and you are passing it a list, not an int. Yourindex
is also 4 times bigger then the size of your array of lists, sointArray[index-3]
reads waaaay beyond the array.I think you overcomplicated it. What you really want here is a plain array or vector of ints. Lists are terribly inefficient for linear access.
Btw. avoid passing strings by value. Pass them as const reference and don't copy them again if you only read from them:
void enCryptMy::EncrpytMy(const QString& encryptText, const QString& localizationToSave)
-
@Chris-Kawa Sorry for getting you into a mistake and for leaving my problem without any further explanation. So, the variable intArray is just a simple Qlist, i forgot to change its name before posting so please, excuse me for that.
For index, it looks like index = w * 4, and after that, there is value = qRgba(intArray[index-3], intArray[index-2], intArray[index-1],intArray[index]);
I know that if the length of my text is not divisible, it's not gonna work. And here the Qlist come in handy. I can check if this number is divisible by 4 and if yes, the code goes as it is now, but when it's not I wanted to add as many items equal to 0 as I need to make it divisible.
Does my explanation makes any sense? I will try try to explain it like that :
if (number is divisible by 4) {
here comes my algorithm for making this image
}
else
{
add as many number as it is needed to make it divisable to qlist and then run the algorithm
}
But then those error appeared and I don't really know how can I get rid of them :/But, how could I make it with vectors? Would it be faster or safer than by using Qlist?
Thanks a lot for help!