Results 1 to 8 of 8

Thread: Problem with QT 4.6 qDebug and QString.

  1. #1
    Join Date
    Nov 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded

    Default Problem with QT 4.6 qDebug and QString.

    If I do the following code I get a compile failure;

    error: no matching function for call to 'qDebug(QString&)'

    QString s = "Test";
    qDebug(s);


    I have tried using qDebug("%s",s) and qDebug(s.toAscii()), but those don't work either.

    I also tried (and I included <QDebug>):

    qDebug << s;

    I am sure this use to work in previous versions.

    I tired a search, but no answer.
    Last edited by weaver4; 10th January 2010 at 21:52.

  2. #2
    Join Date
    Nov 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded

    Default Re: Problem with QT 4.6 qDebug and QString.

    After working with for another hour I found that I can use QString.toLatin1().

    qDebug(s.toLatin1());


    Sorry, but that is flat ugly; there has to be a better way.

  3. #3
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Problem with QT 4.6 qDebug and QString.

    There is. just include #include <QDebug>

    then you can just do qDebug() << str; This works perfectly for me.

    Also you can do qDebug() << qPrintable(str);
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  4. #4
    Join Date
    Nov 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded

    Default Re: Problem with QT 4.6 qDebug and QString.

    It does not work for me. I get this error.

    /home/me/Development/Qt-Projects/PodCastBurner/mainwindow.cpp:63: error: no match for ‘operator<<’ in ‘qDebug << msg’

    Are you using 4.6?

    And yes I did add this line:
    #include <QDebug>

  5. #5
    Join Date
    Sep 2009
    Location
    Finland
    Posts
    63
    Thanks
    1
    Thanked 22 Times in 19 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Problem with QT 4.6 qDebug and QString.

    Quote Originally Posted by weaver4 View Post
    #include <QDebug>
    According to qDebug documentation the file to include is <QtDebug> not <QDebug> and once you have included that file then you should be able to use next format of qDebug:

    Qt Code:
    1. qDebug() << "string";
    To copy to clipboard, switch view to plain text mode 

    Please note the "()" charcters. If that still does not work, please provide a minimal example code with the problem.

  6. #6
    Join Date
    Nov 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded

    Default Re: Problem with QT 4.6 qDebug and QString.

    Nope neither QDebug or QtDebug would cause this statement to work.

    qDebug() << str;

    Same error.

  7. #7
    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: Problem with QT 4.6 qDebug and QString.

    Try this:

    Qt Code:
    1. #include <QtDebug>
    2.  
    3. int main() {
    4. qDebug() << "Testing";
    5. qDebug() << QString("QString works as well");
    6. return 0;
    7. }
    To copy to clipboard, switch view to plain text mode 
    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.


  8. #8
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QT 4.6 qDebug and QString.

    If you're using Qt Creator, goto Projects/ Run Settings/ Run and click checkbox titled "Run in terminal"

Similar Threads

  1. QString problem...
    By Nefastious in forum Newbie
    Replies: 17
    Last Post: 29th September 2009, 16:29
  2. problem in QString
    By wagmare in forum Qt Programming
    Replies: 4
    Last Post: 23rd December 2008, 13:28
  3. QString problem?
    By raphaelf in forum Newbie
    Replies: 7
    Last Post: 24th June 2008, 09:12
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. QString problem
    By vermarajeev in forum Qt Programming
    Replies: 9
    Last Post: 26th October 2006, 19:10

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.