You Are Here:

Community: Wiki

This page was last modified on 30 October 2009, at 16:05.

How to handle individual bits using QBitArray in Qt for Symbian

From Forum Nokia Wiki

Reviewer Approved   




ID ... Creation date 26 January 2009
Platform S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition Tested on devices Emulator
Category Qt for Symbian Subcategory


Keywords (APIs, classes, methods, functions): QBitArray


Overview

This code snippet demonstrates how to handle individual bits in Qt for S60.

Qt provides a QBitArray class which can be use to create an array of the bits. Each bit of this array can be handle saperately. It also supports bitwise AND, OR, NOT, XOR operation similar to the c++.


Preconditions

Various Function

  • Replaces len bytes from index position pos with the byte array after, and returns a reference to this byte array.
QByteArray x("Say yes!");
QByteArray y("no");
x.replace(4, 3, y);
  • Sets the byte array to the printed value of n in base base (10 by default) and returns a reference to the byte array. The base can be any value between 2 and 36.
QByteArray ba;
int n = 63;
ba.setNum(n);      
ba.setNum(n, 16); 
  • Returns the number of bytes in this byte array.
QByteArray ba("Hello");
int n = ba.size();          
ba.data()[0];               
ba.data()[4];               
ba.data()[5];        


Source File

More About QBitArray visit:http://pepper.troll.no/s60prereleases/doc/qbytearray.html

#include <QApplication>
#include <QBitArray>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
 
QWidget *win = new QWidget;
QBitArray x(15,true); // Create a bit arrray x of the size 15 and set all the bits. Second argument is optional.
// Second way to initialize a bit array
QBitArray a;
a.resize(2);
a[0] = false;
a[1] = true;
// Third way to initialize a bit array
QBitArray a(2);
a.setBit(0, false);
a.setBit(1, true);
QBitArray x(4);
x.setBit(2, true);
// x: [ 0, 0, 1, 0 ]
 
QBitArray y(4);
y.setBit(3, true);
// y: [ 0, 0, 0, 1 ]
 
x |= y;//OR operation
// x: [ 0, 0, 1, 1 ]
 
x &= y; // AND operation
// x: [ 0, 0, 0, 1 ]
 
x ^= y; // XOR operation
// x: [ 0, 0, 0, 0 ]
 
x = ~x; // NOT operation
// x: [ 1, 1, 1, 1 ]
 
}

More AboutQBitArray

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fCS001433E5fE2dE5fWatchingE5faE5fYouTubeE5fvideoE5finE5fE51tX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZE71tQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxE71tX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ