PDA

View Full Version : DEBUG version working, release version is not compiling



seux
16th August 2011, 12:54
Hello,
First of all:
I got my code in debug mode compiled, but the compiler says sometimes that one of my functions is defined multiple times with a hint where it is defined for the first time. I checked the code but it is only defined there and thats it. The multiple definition error points me to a moc_ file where the function definition is. So I deleted this code and compiled it a second time and it worked.

Now in release mode:
When i compile it in release mode i get the same errors of multiple definitions. When i click the first defined here error it points me to the code where the functions is defined, as expected. But when I click the multiple definition error, it says that the moc_ file is not found.

Here are the three errors I get:

multiple defintion of `function name`
first defined here
collect2: Id returned 1 exit status


What do I have to do to compile it in release mode?

stampede
16th August 2011, 14:13
The multiple definition error points me to a moc_ file where the function definition is. So I deleted this code and compiled it a second time and it worked.
You deleted something in moc_ file ? This is not a good solution, you should correct your code instead. Maybe you are trying to provide implementation for a signal ?
It'll be easier to help if you show the actual errors and some relevant code.

seux
26th August 2011, 13:22
Okay, here is the code (I shrinked it down cause it would be too much otherwise):

The error has to do with the options box


//OptionsDialog.h
class C_OptionsDialog : public QDialog
{
Q_OBJECT
public:
//...

public slots:
//...

signals:
void setSmoothingGrp(int lvl);

private:
//... widget elements
}

In the constructor i connected the setSmoothingGrp signal like this (same file after the constructor):

connect(sigMapper, SIGNAL(mapped(int)), this, SIGNAL(setSmoothingGrp(int)));
but i also declared the setSmoothingGrp function like this:

void C_OptionsDialog::setSmoothingGrp(int lvl)
{
smoothingLevel = lvl;
currentLab->setText(QString("Current %1").arg(smoothingLevel));
currentLab->update();
}

I think the error occurs because of one time defined as a signal and one time seen as a function :(

when i change the OptionsDialog.h like this, Qt Creator compiles the files fine:

class C_OptionsDialog : public QDialog
{
Q_OBJECT
public:
//...

public slots:
//...

//signals:
//setSmoothingGrp(int lvl);

private:
void setSmoothingGrp(int lvl);
//... widget elements
}

But when i now click one of the buttons nothing happens, the setSmoothing function gets not been executed.

gkarthick5
26th August 2011, 13:34
1. Do not edit the moc_XXX.h files
2. You only need to declare the signals(in the .h file) . You do not (and should not) provide an implementation for it (in the .cpp file). Qt generates the code for signals by itself.

If you remove the function definition in the .cpp file and keep the declaration in the .h file, things should be fine.

nix
26th August 2011, 14:02
The first time you have a signal and a slot with the same name why? Don't do that.

Then once you removed the signal , nothing will happen when you click because you forgot to declare setSmoothingGrp(int) as slots. Try

private slots:
void setSmoothingGrp(int lvl);

I am very surprised your compile fine in debug mode.

seux
26th August 2011, 19:08
@gkarthick5:
When i remove the definition from the cpp file it compiles fine, yeah, but then nothing happens when i click one of the buttons, which makes sense.

Many thanks for your help, I got it working now, nix post pointed me in the right direction :)

But there is a last question i have( I am sure that it was asked already, but i don't really know keywords to make the search useful):
I have got my final release version as an exe file, but it still needs some .dll files to run. Is it possible to make it work without the .dll files, so that it is just the exe file. I am using qt version 4.7.3 and Qt Creator 2.1.0. Do i need something special for this and how difficult is it? If there is already a thread or a site in the Qt documentation, can you just give me the link?