Results 1 to 7 of 7

Thread: Apparently inconsistent compiler behavior

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    63
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Apparently inconsistent compiler behavior

    Hi,
    I'm using Qt Creator to build a GUI application in C++.

    Short description: I get different behavior of the application with apparently the same source code.

    Longer description:

    I tried to store some global data in a separate file, "data.h".
    As a test, I defined a string inside a constructor in that file and wanted to set the text of a QLabel in my main window to that string. I later also added an output (both via qDebug and cout) to the constructor to see it it is called.

    I noticed two things:
    - The string didn't show up in the label upon modifying it in the data.h file. I had to clean the project first.
    - The test output inside the constructor was never shown when running the program.

    I also added a qDebug output along with setting the label's text, which was shown and was always consistent with what the label showed.

    I then reproduced the relevant part of code in a small project "Test" to post here (The project is attached). But in the reduced test version I didn't need to clean the project in order for a modified text to appear in the label right away.

    I went back to the main project and noticed that the inclusion of the file "data.h" was in multiples, so I reduced it to just one. Suddenly both problems were gone, even when I undid the change again ! (Except only the qDebug output worked, not the cout.)

    Then I made some changes to the test project, recompiled, undid them again and recompiled again. I don't remember the exact course of action, but the result was that the apparently exact same program version of the test project once exhibited both problems (i.e. for a short time I needed to clean the project first before an updated string would show), and then went back to the way it was (i.e. just the constructor output didn't happen).

    I have no idea what changes in the source code could have been responsible for the different behaviour. To the best of my memory for both projects the exact same source code version showed different behaviour. I can only assume that some other settings were changed implicitly that I'm not aware of.

    Currently, the main project is working all right. Both problems are gone. But given that I have no explanation what either caused them or let them disappear, I expect something similar to happen again and would like to know what I can do about it the next time.

    Is there any automatic setting that can cause something like that ?

    The Test project is attached. For a quick reference, this is the source code of the data.h file:

    Qt Code:
    1. #ifndef DATA_H
    2. #define DATA_H
    3.  
    4. #include <QString>
    5. #include <QDebug>
    6. #include <iostream>
    7. using namespace std;
    8.  
    9.  
    10. class Files
    11. {
    12.  
    13. public:
    14.  
    15. QString f1;
    16. QString f2;
    17. QString f3;
    18.  
    19. Files()
    20. {
    21. f1 = "test orr";
    22. qDebug() << "Files constructor, " << f1;
    23. cout << "Files constructor" << endl;
    24. f2 = "";
    25. f3 = "";
    26. }
    27.  
    28.  
    29. };
    30.  
    31. extern Files files;
    To copy to clipboard, switch view to plain text mode 


    and the data.cpp file:

    Qt Code:
    1. #include "data.h"
    2.  
    3. Files files;
    To copy to clipboard, switch view to plain text mode 

    The main project only differs in that it has more elements, these being a push button and a menu bar, and that it has another UI file for a submenu that pops up from the menu (which I even deactivated, but that didn't do anything).


    Can you please advise me on which part of the build engine can cause such a problem and where to read up on that ?
    Thank you !
    Attached Files Attached Files

Similar Threads

  1. QT inconsistent performance !!!
    By gontham in forum Qt Programming
    Replies: 7
    Last Post: 12th November 2010, 23:51
  2. Strange compiler behaviour (compiler passes wrong argument)
    By SasaVilic in forum General Programming
    Replies: 2
    Last Post: 2nd November 2010, 11:36
  3. Webpage snapshot program is inconsistent
    By adamkauk in forum Newbie
    Replies: 0
    Last Post: 10th November 2009, 20:04
  4. Replies: 37
    Last Post: 15th July 2009, 22:18
  5. Inconsistent behaviour of QVBoxLayout
    By spraff in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2008, 18:36

Tags for this Thread

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.