Results 1 to 9 of 9

Thread: "not used" warning message for something that _is_ used

  1. #1
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default "not used" warning message for something that _is_ used

    Hi,

    my testprogram works fine, I just wonder why I keep having a warning message.

    I created a new GUI project, and gave one single more header file, which was "stolen" from the chatchedtable exapmle, but I modified the contents of the createconnection file in order to make connection to my own database. So now it looks like this:
    Qt Code:
    1. #ifndef CONNECTION_H
    2. #define CONNECTION_H
    3.  
    4. #include <QtSql/QSqlDatabase>
    5.  
    6. static bool createConnection()
    7. {
    8. QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    9. db.setHostName("myhostname");
    10. db.setPort(5432);
    11. db.setDatabaseName("mydbname");
    12. db.setUserName("myusn");
    13. db.setPassword("mypwd");
    14.  
    15. if (!db.open()) return false;
    16. else return true;
    17. }
    18. #endif // CONNECTION_H
    To copy to clipboard, switch view to plain text mode 

    I included this header to the mainwindow.h with the line
    #include "createconnection.h"
    and there's a simple QSqlTableModel output of a table of my database just to see if it works.

    And that's all. Whenever I compile the project there is the warning message:
    'bool createConnection()' defined but not used
    and I get it twice as if it was detected twice.

    It is pretty wierd as if it wasn't used, the connection shouldn't be estabilished, should it?
    Szilvi

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: "not used" warning message for something that _is_ used

    How exactly do you use it? You're using MSVC, right?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "not used" warning message for something that _is_ used

    well, hard question for an "authodidactic self-encouraged non-student", but I would say no. Or I gues if I have only the Qt environment installed for programming purposes, and I use the Qt Creator then the answer is no. So the most proper answer I can give is that I use the Creator for programming (on XP), and if there is anything installed from the MS things, it must have come with the Qt installer.
    Szilvi

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: "not used" warning message for something that _is_ used

    Tell us how you're using this code. Or better yet attach sources for your complete project to your post.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "not used" warning message for something that _is_ used

    captured. I wanted to make a "pure code" for you, and I deleded some unused lines. As I said I copied the connection header from an in-built example, and I did not really care the included things even if I deleted the lines that would use them. So making the project pure meant also deleting the unnecessary include lines in the connection.h, and the error message misteriously disappeared. However I attach the project to this comment because I would be still interested in the answer why this happens, although this might not be a qt-related topic from this point but rather some programming issue.
    Attached Files Attached Files
    Szilvi

  6. #6
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: "not used" warning message for something that _is_ used

    the problem is keyword static and way you organized your code.
    In this context keyword static mean: this symbol should be visible only in current unit (usually cpp file) and not shared between units.
    Result is that you are defining this symbol again every time you are including this header file. In some source files you are including this header file but you are not using this symbol in this source file (this is why you have a warning).

    You should do it like that:
    In header file:
    Qt Code:
    1. #ifndef CONNECTION_H
    2. #define CONNECTION_H
    3.  
    4. #include <QtSql/QSqlDatabase>
    5.  
    6. bool createConnection(); // declaration of method
    7. #endif // CONNECTION_H
    To copy to clipboard, switch view to plain text mode 

    and in respective cpp file:
    Qt Code:
    1. #include <yourHeaderFile.h>
    2.  
    3. // definition of symbol
    4. bool createConnection()
    5. {
    6. QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    7. db.setHostName("myhostname");
    8. db.setPort(5432);
    9. db.setDatabaseName("mydbname");
    10. db.setUserName("myusn");
    11. db.setPassword("mypwd");
    12.  
    13. if (!db.open()) return false;
    14. else return true;
    15. }
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to MarekR22 for this useful post:

    szisziszilvi (5th April 2011)

  8. #7
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "not used" warning message for something that _is_ used

    But I include the header only once: in the mainwindow.h.

    Your version works fine, but I'm still confused a bit as in this case stricly speaking the line
    #include "myconnection.h"
    appears twice, once in mainwindow.h and once in createconnection.cpp.
    Szilvi

  9. #8
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: "not used" warning message for something that _is_ used

    Quote Originally Posted by szisziszilvi View Post
    But I include the header only once: in the mainwindow.h.
    Remember that only cpp files are compiled directly! Header files are compiled only when they are included to source file (cpp), directly or by other header file, so they may be compiled more then once.
    Your header may appeared only once in mainwindow.h but this mainwindow.h appeared many times in some source files (probably in mainwindow.cpp and main.cpp - maybe in other cases too I didn't check your full code).

  10. #9
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "not used" warning message for something that _is_ used

    ahha!
    thanks!
    Szilvi

Similar Threads

  1. Replies: 7
    Last Post: 8th November 2012, 11:26
  2. "unknown editor" warning message from XP
    By fragolan in forum Installation and Deployment
    Replies: 2
    Last Post: 6th April 2010, 11:33
  3. Replies: 5
    Last Post: 19th April 2009, 13:24
  4. Replies: 4
    Last Post: 12th October 2008, 13:47
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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.