3

I just started using Qt Creator 3.5.0, Qt 5.4.2 with GCC on Kubuntu 15.10. I created a new project, added a window and currently I am trying to develop a new module.

However strange things happen.

I wrote a debug output line in my template class X. The line is located in a function of class X in the header of its module, e.g.:

qDebug() << "Hello1" << endl;

After building and running the application this line is executed and "Hello1" is printed in the debug console as desired. Also I can use the debugger and step through the line. When building the application the compiler does essentially nothing since no code file was changed (as expected).

When editing the above line things go weired:

  • I changed the line to "Hello2" and saved the code file.
  • I could see the correctly updated file modification date/time of the source file and I verified that the file is newer than the corresponding object file.
  • When buildung the project the compiler actually compiled the edited source file and linked the application as expected. I verified the updated object file date/time and the update executeable file date/time.
  • However when starting the application the behavior did NOT change! The output is still "Hello1".
  • When searching through the executeable using a binary editor I can still see the old string "Hello1" only. No other string containing "Hello".
  • After doing the above again (changing the line to "Hello3") still "Hello1" is printed.

More facts:

  • When re-building the entire application or after cleaning the project the change takes effect a single time.
  • The problem is reproducible every time on every edit.
  • I couldn't observe this with any other module, it happens with that one source module only that seems not to be different in a significant way.
  • As mentioned the code line is located in the module header. But modifing the module itself doesn't change anything.
  • Changing class X and a second module at the same time does not change anything (modification in the second module takes effect, modification in class X doesn't have an effect).
  • Both header and module were correctly added to the .pro file.
  • Restarting QtCreator does not change anything.
  • This happens with and without debugger.
  • Makefile rules for the class X module look sensible and are not different than the rules of other modules.

I have no idea how this is possible. Maybe I missed something obvious. Any ideas?

UPDATE: Using system monitor I could confirm that the running process uses the expected executeable.

Silicomancer
  • 8,604
  • 10
  • 63
  • 130
  • Is the header found via a INCLUDEPATH directive? Then check if you’re running into this: http://stackoverflow.com/questions/5470438/why-are-changes-in-source-not-always-reflected-in-machine-code-after-build-while (otherwise add your .pro file) – Frank Osterfeld Dec 24 '15 at 10:44
  • Why -1? Please explain. – Silicomancer Dec 24 '15 at 12:59
  • @Frank: That does not apply to my case. My header is in the project root which is not explicitely mentioned in INCLUDEPATH. However editing the .pro file (without changing anything!) seems to have fixed the issue somehow. No idea why. I will observe the behavior. – Silicomancer Dec 24 '15 at 13:06

5 Answers5

2

You can try some things:

  1. Check if the exe your are opening its on the same path as the created one (you can verify it looking into .pro.user file.
  2. Check if when you compile, it does save the changes first and then compile it together otherwise it may seem it does it but don't.
  3. If you have changed your .pro file run qmake and build it again.
  4. Try cleaning, runing qmake and re-building the project.
  5. If you changed your .pro file or you are including external libs or files, check the output log to see if everything is ok, sometimes it is not but stills compiles (and then doesn't link well or just let you the old compiled version).

It seems to be compiling the last 'version' of your code and not applying the changes for some of that reasons and others (If I think in other things I'll edit the post later).

Hope it helps

Megasa3
  • 766
  • 10
  • 25
  • Exe is the same. I saved manually so save happens before build. However it seems that editing the .pro file (without changing anything) fixed the behavior. Hope this is permanently. Anyway this is strange. – Silicomancer Dec 24 '15 at 13:08
1

Check which exe the debugger is actually running. It may be another copy! Look at a process listing to know for sure what EXE is under the debugger.

This general issue has happened for various reasons in my personal experience. Files get copied to an install/staging area; the environment shadows things; the wrong project is set to "start up"; the way the component is run when starting the debug session ends up resolving to the wrong file; the wrong configuration or flavor is being changed; etc.

Rule 1: verify your assumptions. You checked file dates etc. but add to that checking what file (full path) is actually under the debugger.

JDługosz
  • 5,592
  • 3
  • 24
  • 45
1

Modify your main.cpp and recompile this should update your code. Not sure why this is happening but I add a cout << "Ver: 1 \n"; and update the number every time I change the header file. This seems to be a workaround.

JRG
  • 11
  • 1
1

Problem still exists under Qt 5.8:

This problem continues to arise with Qt 5.8 using clang, building 64-bit for OSX, under OSX, from within Qt Creator. So it's not a GCC issue.

Solution:

I was able to get dependent compiles to respond correctly to changes to a newly added header file by:

  • Cleaning the project
  • Running QMake
  • Rebuilding the entire project.

Checks:

Before doing the above, I checked the project file and made sure that the new file was listed in the HEADERS section (it was.) Despite this, Qt would not rebuild the file that included the .h file.

fyngyrz
  • 2,458
  • 2
  • 36
  • 43
0

I've experienced this issue as well. I was able to resolve it by cleaning (in my case running catkin clean) and then re-building it (catkin_make).

Unfortunately I haven't been able to figure out the exact cause of the problem, but hopefully someone more knowledgeable has an idea.

In addition, my development environment is different (Ubuntu 14.04, Qmake 3.1, Qt 5.9.1, gcc 4.8.4, catkin tools 0.4.4, Qt Creator etc) so obviously my fix may not work for everyone.

Matt
  • 57
  • 8