Results 1 to 11 of 11

Thread: QByteArray sample in doc error!

  1. #1
    Join Date
    Jan 2012
    Posts
    13
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QByteArray sample in doc error!

    Hello,

    I read in Qbytesarray doc and try this code,

    QByteArray ba;
    ba.resize(5);
    ba[0] = 0x3c;
    ba[1] = 0xb8; ->
    ba[2] = 0x64;
    ba[3] = 0x18;
    ba[4] = 0xca;->

    but appear it's show error and can only input until "0x7f" or 127, how if I want to input data for example "0xff".


    thanks

  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: QByteArray sample in doc error!

    Works for me...

    Qt Code:
    1. #include <QtDebug>
    2. #include <QByteArray>
    3. #include <stdio.h>
    4.  
    5. int main(int argc, char **argv) {
    6. QByteArray ba = "\x3c\xb8\x64\x18\xca";
    7. for(int i=0;i<ba.size();++i) {
    8. printf("%d: %x\n", i, (unsigned char)ba.at(i));
    9. }
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 


    0: 3c
    1: b8
    2: 64
    3: 18
    4: ca
    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
    Jan 2012
    Posts
    13
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray sample in doc error!

    Hi wysota..thanks

    yes it's works, but can you enlighten me why in first sample it's show warning (but actually if we debug the result is ok) than your sample?.

  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: QByteArray sample in doc error!

    I haven't seen the warning so I won't guess.
    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
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QByteArray sample in doc error!

    No warnings here:
    Qt Code:
    1. #include <QtCore>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char **argv) {
    5. QCoreApplication app(argc, argv);
    6.  
    7. ba.resize(5);
    8. ba[0] = 0x3c;
    9. ba[1] = 0xb8;
    10. ba[2] = 0x64;
    11. ba[3] = 0x18;
    12. ba[4] = 0xca;
    13. qDebug() << ba.toHex();
    14.  
    15. return 0;
    16. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. $ make
    2. g++ -c -pipe -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o main.o main.cpp
    3. g++ -Wl,-O1 -Wl,-rpath,/usr/lib64/qt4 -o test main.o -L/usr/lib64/qt4 -lQtGui -L/usr/lib64 -L/usr/lib64/qt4 -L/usr/X11R6/lib -lQtCore -lgthread-2.0 -lrt -lglib-2.0 -lpthread
    4. $ ./test
    5. "3cb86418ca"
    To copy to clipboard, switch view to plain text mode 

    Perhaps tell us what environment and compiler you are using, and what the warnings actually are.

  6. #6
    Join Date
    Jan 2012
    Posts
    13
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray sample in doc error!

    sorry just got to forum again..

    I'm in windows.. from chris example I got this ouput error :

    Running build steps for project testing...
    Configuration unchanged, skipping qmake step.
    Starting: "D:\QtSDK\QtCreator\bin\jom.exe"
    D:\QtSDK\QtCreator\bin\jom.exe -nologo -j 4 -f Makefile.Debug
    cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\..\Desktop\Qt\4.7.4\msvc2008\include\QtCor e" -I"..\..\Desktop\Qt\4.7.4\msvc2008\include" -I"..\..\Desktop\Qt\4.7.4\msvc2008\include\ActiveQt " -I"debug" -I"..\..\Desktop\Qt\4.7.4\msvc2008\mkspecs\win32-msvc2008" -Fodebug\ @C:\Users\yandikbo\AppData\Local\Temp\main.obj.507 2.0.jom
    main.cpp
    main.cpp(11) : warning C4309: 'argument' : truncation of constant value
    main.cpp(14) : warning C4309: 'argument' : truncation of constant value
    link /LIBPATH:"d:\QtSDK\Desktop\Qt\4.7.4\msvc2008\lib" /NOLOGO /DEBUG /SUBSYSTEM:CONSOLE /MANIFEST /MANIFESTFILE:"debug\testing.intermediate.manifest" /OUT:debug\testing.exe @C:\Users\yandikbo\AppData\Local\Temp\testing.exe. 5072.827.jom
    mt.exe -nologo -manifest "debug\testing.intermediate.manifest" -outputresource:debug\testing.exe;1

    jom 1.0.6 - empower your cores

    The process "D:\QtSDK\QtCreator\bin\jom.exe" exited normally.

  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: QByteArray sample in doc error!

    Apparently your compiler treats those constants as ints. Try surrounding them in quotes. '\x68' instead of 0x68).
    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 2012
    Posts
    13
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray sample in doc error!

    aaahhh....ok
    it's working now without error....thanks

  9. #9
    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: QByteArray sample in doc error!

    It was a warning, not an error. The compiler was merely informing you that the implicit conversion looses information which is ok in this case.
    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.


  10. #10
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QByteArray sample in doc error!

    what`s the difference between '\x68' and 0x68? one is a char* and the other one too right?

  11. #11
    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: QByteArray sample in doc error!

    No. First one is a char (single quotes), the other is a constant which your compiler interprets as an integer.
    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.


  12. The following user says thank you to wysota for this useful post:

    KillGabio (2nd February 2012)

Similar Threads

  1. Replies: 1
    Last Post: 22nd June 2011, 08:12
  2. QWebView and QByteArray: encoding error
    By missoni in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 16th May 2011, 22:41
  3. Replies: 4
    Last Post: 18th November 2010, 13:00
  4. Qt Creator Error running sample - wrong path for pythongdb
    By Asperamanca in forum Qt Tools
    Replies: 3
    Last Post: 6th October 2010, 20:33
  5. Replies: 9
    Last Post: 25th July 2009, 13:27

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.