[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

QColorDialog with Initial Color -> Access Violation

Posted on 2012-08-14
10
Medium Priority
?
1,417 Views
Last Modified: 2012-08-29
I've started to use QT 4.8 and i'm trying to show a QColorDialog with an initial color taken from a config file, and once the user selected the color, it write it back to this file.

I'm getting Access Violation all the time when i try to pass it an initial color that i've set like this for example:

            QColor wTmpCol = QColor::fromRgb(0,0,0,255);
            QColor wColor = QColorDialog::getColor(wTmpCol, this);

When i pass a Qt::white or any Qt::SomethingElse it work.

How can i solve this problem?

Thanks
0
Comment
  • 5
  • 5
10 Comments
 
LVL 7

Expert Comment

by:irfan_omair
ID: 38293680
Are you getting some kind of compilation error? or warning or run time thing?

Can you please post exact message about violation.
0
 
LVL 7

Expert Comment

by:irfan_omair
ID: 38293688
also on what platform are you geting this message
0
 
LVL 10

Author Comment

by:Christian de Bellefeuille
ID: 38293773
There's no compilation error or warning.  It's running on Windows 7.

But i was wrong about one thing... i thought it was working with Qt::white, but it's not working either.  

I get this "First-Chance exception... Access violation reading location 0xfeeefeee" at the end of my Slot.  Here's the code for the slot, i've no exception on any line in it.

void Setup::onColorPickerClick()
{
   QColor wTmpCol = QColor::fromRgb(0,0,0,255);
   QColor wColor = QColorDialog::getColor(Qt::white, this);
		
   if (wColor.isValid())
   {
      mUi.qpbColorPicker->setPalette(QPalette(wColor));
      mUi.qpbColorPicker->setAutoFillBackground(true);		
   }
}

Open in new window


Here's how i connect the signal to the slot:
QObject::connect(mUi.qpbColorPicker, SIGNAL(clicked()), this, SLOT(onColorPickerClick()));
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Assisted Solution

by:irfan_omair
irfan_omair earned 2000 total points
ID: 38294310
There could be two suspected Issue I can think of.
One either you are using old compiler with newer version of Qt or
Your object in Your slot is not valid (either deleted or not having memory)
0
 
LVL 10

Author Comment

by:Christian de Bellefeuille
ID: 38294386
I'm using Visual Studio 2010, and i've plenty of available memory.
The code inside that Slot doesn't trigger any error or warning... if an object wouldn't be correct, my guess is that it would give me an error inside the slot.

Instead of that, after hitting the last bracket, it go thru few QT calls then end-up in qaccessible.cpp, in queryAccessibleInterface and crash on that line:
const QMetaObject *mo = object->metaObject()
0
 
LVL 7

Expert Comment

by:irfan_omair
ID: 38294562
Okay I will try to reproduce the same at my end and will try to find some solution.
meanwhile is this possible for you to put up small working example here so that I can run that and see the crash at my end.
0
 
LVL 10

Author Comment

by:Christian de Bellefeuille
ID: 38301782
Actually, this is a part of a big project and it would be difficult to put it in here.
I'll try to make a small version of it.  One of my coworker who created this environment will take a look at it tomorrow to see if we can solve this.  I'll keep you in touch.
0
 
LVL 7

Expert Comment

by:irfan_omair
ID: 38301804
I am also pretty much tight at my work before going on vacation so could nt get time to write something for this. Sorry
but if you can send something I am sure I will be able to figure it out. I still feel like the object has invalid memory
0
 
LVL 10

Accepted Solution

by:
Christian de Bellefeuille earned 0 total points
ID: 38330670
Sorry for the long silence.  I had more urgent mather than QColorDialog.

I've never been able to figure out how to make this sample from Nokia website work (the example that I've provided), but i've managed to make it work.  I had a feeling that it had something to do with the blocking function QColorDialog::getColor.

Here's what i've done.  First, my app couldn't wait for the user to pick-up a color... it had to stay "responsive".  

I've declared my QColorDialog in my class (the mDlgColor member).
Then i've connected my signals to show that dialog with "mDlgColor.open()"
And finally, i trap the colorSelected from the QColorDialog.  This is triggered when the user press OK in the QColorDialog

So here's my code...

QObject::connect(mUi.ColorPicker, SIGNAL(clicked()), this, SLOT(onColorPickerClick()));
QObject::connect(&mDlgColor, SIGNAL(colorSelected(QColor)), this, SLOT(onColorSelected(QColor)));

void Options::onColorPickerClick()
{
    mDlgColor.open();
}

 void Options::onColorSelected(QColor iColor)
 {
     if (iColor.isValid())
      {
          // Do whatever you want here
      }
}

Open in new window



Thanks a lot for the hints you have provided.
0
 
LVL 10

Author Closing Comment

by:Christian de Bellefeuille
ID: 38344716
I don't know if it's ok to give points to someone who helped and mark our own solution as the answer.  It's just to not mislead readers and save them some time.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Simple Linear Regression
Progress
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question