Results 1 to 8 of 8

Thread: QVariant::QVariant(Qt::GlobalColor)' is private

  1. #1
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QVariant::QVariant(Qt::GlobalColor)' is private

    declaration in header file

    Qt Code:
    1. QColor dialogBoja, dialogBoja1;
    To copy to clipboard, switch view to plain text mode 

    .cpp file
    Qt Code:
    1. dialogBoja = postavke.value("boja", Qt::black).toString();
    2. //postavke means settings
    3. dialogBoja1 = postavke.value("boja1", Qt::white).toString();
    To copy to clipboard, switch view to plain text mode 

    As I said on title, when I try to compile this in Qt5 I get error: QVariant::QVariant(Qt::GlobalColor)' is private

    How to solve this.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QVariant::QVariant(Qt::GlobalColor)' is private

    Use
    Qt Code:
    1. QVariant(Qt::black)
    To copy to clipboard, switch view to plain text mode 

    EDIT: But your code will even with this not compile since you are trying to set a QString on a QColor...

  3. #3
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QVariant::QVariant(Qt::GlobalColor)' is private

    Quote Originally Posted by Lykurg View Post
    Use
    Qt Code:
    1. QVariant(Qt::black)
    To copy to clipboard, switch view to plain text mode 

    EDIT: But your code will even with this not compile since you are trying to set a QString on a QColor...
    This code only saves current color in settings file.

    Is this what you mean? dialogBoja = postavke.value("boja", QVariant(Qt::black)).toString();

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QVariant::QVariant(Qt::GlobalColor)' is private

    Yes, but you can store QColor direct to QSetting without transforming it to a string.

  5. #5
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QVariant::QVariant(Qt::GlobalColor)' is private

    Yes I know, but I need it this way. I get the same error like before.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QVariant::QVariant(Qt::GlobalColor)' is private

    Why are you trying to set a QColor by converting a QSettings value to a QString? It looks like all you want is to set a default color if the QSettings does not contain an entry for your query. So do this:

    Qt Code:
    1. dialogBoja = postavke.value("boja", QColor( Qt::black ) ).value<QColor>();
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QVariant::QVariant(Qt::GlobalColor)' is private

    Thanks, it's working after adding QColor(Qt::black). But let me explain you why I convert it to string:

    dialogBoja = QColorDialog::getColor(Qt::black, this);
    edit->setStyleSheet(QString("color:%1").arg(dialogBoja. name()));

    That's how I use this color, maybe it's wrong but that's how I made it and I don't want to change 1600 line of code )

    Thanks for your help.

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QVariant::QVariant(Qt::GlobalColor)' is private

    So next time, abstract this to something more easily changed, like:

    Qt Code:
    1. void setWidgetStyleSheetColor( QWidget * w, const QColor & c )
    2. {
    3. w->setStyleSheet(QString("color:%1").arg(c.name()));
    4. }
    To copy to clipboard, switch view to plain text mode 

    and use that method call instead of your 1600 lines of hard-coding. If you find a better way of doing it, you have only one line to change.

    By the way, I don't think that setting the color by name as you are doing has any effect on the string returned by the name() method. The name() method will take whatever RGBA value the internal representation is holding and turn it into a #RRGGBB string. It also looks like the name() methods strips off any alpha channel, so that will have undesirable consequences for your style sheet if you decide to use semi-transparent colors.

Similar Threads

  1. Replies: 4
    Last Post: 4th January 2011, 12:07
  2. How to use QVariant with enum?
    By FinderCheng in forum Qt Programming
    Replies: 1
    Last Post: 25th December 2010, 21:23
  3. Replies: 1
    Last Post: 4th December 2009, 17:03
  4. a question about QVariant
    By calmspeaker in forum Qt Programming
    Replies: 4
    Last Post: 14th August 2009, 07:42
  5. QTextCharFormat and QVariant
    By fullmetalcoder in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2007, 11:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.