[SOLVED] Saving custom user settings in Qt
-
Thank you both for your help and for the good information provided.
[quote author="Josué V. Herrera" date="1344392547"]You didn't specify the class to which these methods belong, and this is mandatory. Based in your example the declaration should look like this:
.cpp file:
@inline void MainWindow::setColor(const QObject &myCurrentColor)
{
myColor = myCurrentColor;
}inline const QColor& MainWindow::getColor()
{
return myColor;
}@
[/quote]Well I actually forgot to add that in my example but I have tried that before and I keep getting errors.
error: no matching function for call to 'MainWindow::setColor(QColor&)
candidates are: void MainWindow::setColor(const QObject&)
In member function 'void MainWindow::setColor(const QObject&)':error: no match for 'operator=' in '((MainWindow*)this)->MainWindow::myColor = myCurrentColor'
candidates are: QColor& QColor::operator=(const QColor&)
note:QColor& QColor::operator=(Qt::GlobalColor)Any idea what could be causing these errors?
Thanks a lot
-
Read carefully. The errors quite clearly state what the problem is.
-
bq. error: no matching function for call to ‘MainWindow::setColor(QColor&)
I do have that function!
Sorry if I dont see the obvious.
-
is it possible QmlApplicationViewer can be used or manipulated in other class rather than main.
-
[quote author="fs_tigre" date="1344421000"]bq. error: no matching function for call to ‘MainWindow::setColor(QColor&)
I do have that function!
Sorry if I dont see the obvious.
[/quote]No, you don't have that function. From your error (my highlight):
[quote author="fs_tigre" date="1344420694"]error: no matching function for call to 'MainWindow::setColor(QColor&)
candidates are: void MainWindow::setColor(const QObject&)
In member function 'void MainWindow::setColor(const QObject&)':
[/quote]What makes you think QColor& is the same as a const QObject&?
And, while we're at it: QObject cannot be copied, so you cannot use it as a function argument the way you do. Pass around pointers instead.
-
Oh, I see, I do have setColor function but I'm passing a different parameter of what was specified in the header which makes it a completely different function. I was just using the code provided by Josué V. Herrera, and to be quite honest, if that's wrong I wont be able to find a solution or fix the problem. I do understand the error but I do not know the solution.
Thanks
-
Code people give you here on the forum is usually not mend to be used as-is. Often, it is "brain-to-terminal": something you quickly write down in the forum editor itself, untested and probably even not compiling. The idea of such code is that it is a teaching tool; a way of pointing you towards a solution, but often not the solution itself. Copy pasting such snippets is not learning, as it does not promote understanding. If you can only solve your issue by using completely ready-made code offered by others, then you have a serious problem that can only be solved by either really starting to study, or by shelling out some money to start paying a consultant to help you with your project.
-
Understood, Thanks.
I have said this a few times, I already took a c++ class, read a Qt book but some times is just hard to get everything understood in less than a year. I do programming as a hobby, I actually work full time as Mechanical Engineer.
On this case I think my problem is a poor understanding of C++ in general but pass by reference and pointers are the main issue in this situation.
I know I know, sorry for the time you guys wasted here.
Thanks a lot for all of your previous help.
-
I cannot believe it, it's working, after a few hours, I finally made this thing work.
Made a few changes including, changing @inline void setColor(const QObject &myCurrentColor);@ to @void setColor(const QColor &myCurrentColor);@
Even though it doesn't seem like I want to learn, I do, but sometimes it's hard, especially when you are not a programmer.
Thanks a lot to all that helped.
-
I didn't say nothing about using inline functions in implementation files, because I was not sure why I always use it at headers. Obviously I read it in some book and now I do it without thinking.
I'm sorry about my mistake specifying QObject instead of QColor, as Andre said that was “brain-to-terminal”, just an example, a possible solution.
Glad to hear that finally you got it.
Note: I'm not sure if I should correct my snippet of code for future readers. I think this could break the sequence of the posts. Andre, what do you think about this?
-
How would you format the color as a QColor entry in an INI type file?
I want to read in a value from the file to set the initial color
-
How would you format the color as a QColor entry in an INI type file?
I want to read in a value from the file to set the initial color