Skip to main content
GameDev.net gamedev.net
🔒 Locked

Stupid error or QT error?

Started by flukus Dec 19, 2004 at 4:25 AM 4 replies 850+ views
Original Post
flukus
flukus
Hi, I'm currently dusting off my c++ skills (or lack thereof) and learning qt while I'm at it. Now, on to my question, and I think it's a simple one. In My class declaration I have a nice simple: int currentColour; which is set to 0 during the class destructor, then I have a function: void Row::setColour(int colour) { currentColour = colour; printf("in Row::setColour %X \n", currentColour); } which, naturally sets currentColour to whatever I pass in, printf 'proves' this. But then when another function gets called (a qt slot) void Row::btnClicked(void) { printf("Setting one to palette %X \n", currentColour); } currentColour is ALWAYS what it was set to in the constructor. So I think I've either done something stupid or I'm missing something about what moc (a qt file conversion thingy) does to my sockets. To eliminate the chance of it being the former I've searched through the file to find all instances of currentColour, so I'm not overwriting it anywhere, and it's a private member so it's not being overwritten anywhere. So, can anyone help me with this? I'm stumped that something so straighforward can cause sucha headache!
flukus
flukus
Well, it's a qt problem. moc or qmake does something with slots that forbids me from calling member functions or changing class properties (reading them is fine). I'm still looking for a way around this!
kuphryn
kuphryn
Post the code that connects slot btnClicked() to a signal from the button widget.

Kuphryn
flukus
flukus
QObject::connect(buttons, SIGNAL(clicked()), this, SLOT(btnClicked() ) );

Thats how it's done in all the tutorials, unless I'm missing something.
kuphryn
kuphryn
Make sure you're calling setColour() for buttons.

Kuphryn
SAE Superman
SAE Superman
Quote:
Original post by flukus
Well, it's a qt problem. moc or qmake does something with slots that forbids me from calling member functions or changing class properties (reading them is fine). I'm still looking for a way around this!


I assure you it's not a Qt problem. I work with Qt professionally and I've only found one bug in it and it may even be fixed in version 4 when it comes out in a few months. Give more info about your problem and I can maybe help. A word of advise, don't ever touch the moc files or any other Qt generated file. Anything you change in the generated .cpp files (if you use Qt designer) will be overwritten the next time you compile and the same goes for the moc files. If you write your code properly, you should never have to touch them.

From what I can guess with what info you gave, you are having a connection problem. Give a little background on what you're doing and I might be able to write an example for you. You should only have to implement the slots. Signals you emit, you do nothing with (these are one of the things that get generated in the moc files).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.