Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing QFile to function

I get an illegal indirection error at generateCSVHeader(*file4);.

function declaration:

void generateCSVHeader(QFile * file);

function use:

str="MyData.csv";
QFile file4(str);
generateCSVHeader(*file4);

when I drop the dereference designator, it gives me a cannot convert QFIle to QFile * error.

like image 299
moesef Avatar asked Jul 27 '26 11:07

moesef


1 Answers

You should pass pointer to your QFile object (which is an address) instead of passing the object itself (dereferencing is irrelevant, because it is used only with pointers, not objects). To get an address of your object, you should use the & operator. So you have to invoke your function like this:

generateCSVHeader(&file4)

Also, you may consider using references instead of pointers.

like image 99
nameless Avatar answered Jul 30 '26 05:07

nameless



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!