<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # QByteArray Class Reference ## [[QtCore](index.htm) module] The QByteArray class provides an array of bytes. [More...](#details) ### Methods * `__init__ (self)` * `__init__ (self, int?size, str?c)` * `__init__ (self, QByteArray?a)` * `QByteArray append (self, QByteArray?a)` * `QByteArray append (self, QString?s)` * `str at (self, int?i)` * `int capacity (self)` * `chop (self, int?n)` * `clear (self)` * `bool contains (self, QByteArray?a)` * `int count (self, QByteArray?a)` * `int count (self)` * `str data (self)` * `bool endsWith (self, QByteArray?a)` * `QByteArray fill (self, str?ch, int?size?=?-1)` * `int indexOf (self, QByteArray?ba, int?from?=?0)` * `int indexOf (self, QString?str, int?from?=?0)` * `QByteArray insert (self, int?i, QByteArray?a)` * `QByteArray insert (self, int?i, QString?s)` * `bool isEmpty (self)` * `bool isNull (self)` * `int lastIndexOf (self, QByteArray?ba, int?from?=?-1)` * `int lastIndexOf (self, QString?str, int?from?=?-1)` * `QByteArray left (self, int?len)` * `QByteArray leftJustified (self, int?width, str?fill?=?' ', bool?truncate?=?False)` * `int length (self)` * `QByteArray mid (self, int?pos, int?length?=?-1)` * `QByteArray prepend (self, QByteArray?a)` * `push_back (self, QByteArray?a)` * `push_front (self, QByteArray?a)` * `QByteArray remove (self, int?index, int?len)` * `QByteArray repeated (self, int?times)` * `QByteArray replace (self, int?index, int?len, QByteArray?s)` * `QByteArray replace (self, QByteArray?before, QByteArray?after)` * `QByteArray replace (self, QString?before, QByteArray?after)` * `reserve (self, int?size)` * `resize (self, int?size)` * `QByteArray right (self, int?len)` * `QByteArray rightJustified (self, int?width, str?fill?=?' ', bool?truncate?=?False)` * `QByteArray setNum (self, int?n, int?base?=?10)` * `QByteArray setNum (self, float?n, str?format?=?'g', int?precision?=?6)` * `QByteArray setNum (self, int?n, int?base?=?10)` * `QByteArray setNum (self, int?n, int?base?=?10)` * `QByteArray simplified (self)` * `int size (self)` * `list-of-QByteArray split (self, str?sep)` * `squeeze (self)` * `bool startsWith (self, QByteArray?a)` * `swap (self, QByteArray?other)` * `QByteArray toBase64 (self)` * `(float, bool?ok) toDouble (self)` * `(float, bool?ok) toFloat (self)` * `QByteArray toHex (self)` * `(int, bool?ok) toInt (self, int?base?=?10)` * `(int, bool?ok) toLong (self, int?base?=?10)` * `(int, bool?ok) toLongLong (self, int?base?=?10)` * `QByteArray toLower (self)` * `QByteArray toPercentEncoding (self, QByteArray?exclude?=?QByteArray(), QByteArray?include?=?QByteArray(), str?percent?=?'%')` * `(int, bool?ok) toShort (self, int?base?=?10)` * `(int, bool?ok) toUInt (self, int?base?=?10)` * `(int, bool?ok) toULong (self, int?base?=?10)` * `(int, bool?ok) toULongLong (self, int?base?=?10)` * `QByteArray toUpper (self)` * `(int, bool?ok) toUShort (self, int?base?=?10)` * `QByteArray trimmed (self)` * `truncate (self, int?pos)` ### Static Methods * `QByteArray fromBase64 (QByteArray?base64)` * `QByteArray fromHex (QByteArray?hexEncoded)` * `QByteArray fromPercentEncoding (QByteArray?input, str?percent?=?'%')` * `QByteArray fromRawData (str)` * `QByteArray number (int?n, int?base?=?10)` * `QByteArray number (float?n, str?format?=?'g', int?precision?=?6)` * `QByteArray number (int?n, int?base?=?10)` * `QByteArray number (int?n, int?base?=?10)` ### Special Methods * `QByteArray __add__ (self, QByteArray?a2)` * `QString __add__ (self, QString?s)` * `int __contains__ (self, QByteArray?a)` * `bool __eq__ (self, QString?s2)` * `bool __eq__ (self, QByteArray?a2)` * `bool __ge__ (self, QString?s2)` * `bool __ge__ (self, QByteArray?a2)` * `str __getitem__ (self, int?i)` * `QByteArray __getitem__ (self, slice?slice)` * `bool __gt__ (self, QString?s2)` * `bool __gt__ (self, QByteArray?a2)` * `int __hash__ (self)` * `QByteArray __iadd__ (self, QByteArray?a)` * `QByteArray __iadd__ (self, QString?s)` * `QByteArray __imul__ (self, int?m)` * `bool __le__ (self, QString?s2)` * `bool __le__ (self, QByteArray?a2)` * `__len__ (self)` * `bool __lt__ (self, QString?s2)` * `bool __lt__ (self, QByteArray?a2)` * `QByteArray __mul__ (self, int?m)` * `bool __ne__ (self, QString?s2)` * `bool __ne__ (self, QByteArray?a2)` * `str __repr__ (self)` * `str __str__ (self)` * * * ## Detailed Description 這個類可以醃制。 可以使用Python的字符串對象,每當一個[QByteArray](qbytearray.html)預計。 該QByteArray中的類提供了一個字節數組。 QByteArray中可以用來存儲原始字節(包括'\ 0的)和傳統的8位'\ 0'結尾的字符串。使用QByteArray中遠遠比使用更方便`const char *`。在幕后,它始終確保數據后跟一個'\ 0 '終止和用途[implicit sharing](index.htm)(復制上寫的),以減少內存使用量,避免數據的不必要的復制。 除了QByteArray中, Qt還提供了[QString](qstring.html)類存儲字符串數據。對于大多數用途,[QString](qstring.html)是您要使用的類。它存儲16位的Unicode字符,使得它易于保存non-ASCII/non-Latin-1字符在你的應用程序。此外,[QString](qstring.html)用于整個Qt的API中。兩個主要的情況下, QByteArray中是合適的,當你需要存儲原始二進制數據,而當內存保護是至關重要的(例如,用Qt嵌入式Linux的) 。 初始化一個QByteArray中的一種方法是簡單地傳遞一個`const char *`它的構造函數。例如,下面的代碼創建一個包含數據的“Hello ” 5大小的字節數組: ``` QByteArray ba("Hello"); ``` 雖然[size](qbytearray.html#size)( ) 5 ,字節數組也是在年底維持一個額外的'\ 0 '字符,這樣,如果一個函數使用的要求一個指向基礎數據(如調用[data](qbytearray.html#data)( ) ) ,指向的數據保證是'\ 0'結尾的。 QByteArray中做的一個深層副本`const char *`數據,所以你可以在以后修改它沒有遇到的副作用。 (如果由于性能原因你不希望采取的字符數據,使用深拷貝[QByteArray.fromRawData](qbytearray.html#fromRawData)( )來代替。 ) 另一種方法是利用設置在陣列的大小[resize](qbytearray.html#resize)()和初始化每字節的數據字節。 QByteArray中使用基于0的索引,就像C + +中的數組。要訪問在特定索引位置的字節,你可以使用operator [] ( ) 。對非const字節數組,操作符[ ] ( )返回一個引用,可以在賦值的左側使用一個字節。例如: ``` QByteArray ba; ba.resize(5); ba[0] = 0x3c; ba[1] = 0xb8; ba[2] = 0x64; ba[3] = 0x18; ba[4] = 0xca; ``` 對于只讀訪問,另一種語法是使用[at](qbytearray.html#at)(): ``` for (int i = 0; i < ba.size(); ++i) { if (ba.at(i) >= 'a' && ba.at(i) <= 'f') cout << "Found character in range [a-f]" << endl; } ``` [at](qbytearray.html#at)( )可以比的operator [ ] ( )快,因為它不會導致一個[deep copy](index.htm#deep-copy)發生。 要一次提取多少字節,使用[left](qbytearray.html#left)( )[right](qbytearray.html#right)() ,或[mid](qbytearray.html#mid)( ) 。 一個QByteArray中可以嵌入'\ 0 '字節。該[size](qbytearray.html#size)( )函數總是返回整個數組,包括嵌入式'\ 0'的字節大小。如果你想獲得的數據備份到不包括第一個' \ 0 '字符,通話時長[qstrlen](index.htm#qstrlen)( )的字節數組。 調用后[resize](qbytearray.html#resize)( ) ,新分配的字節都未定義的值。要設置所有字節到一個特定的值,調用[fill](qbytearray.html#fill)( ) 。 為了獲得一個指向實際的字符數據,調用[data](qbytearray.html#data)()或[constData](qbytearray.html#constData)( ) 。這些函數返回一個指針,該數據的開頭。指針是保證仍然有效,直到一個非const函數被調用的QByteArray中。它也保證了數據與'\ 0'字節結束,除非QByteArray中是從創建[raw data](qbytearray.html#fromRawData)。這個'\ 0'字節由QByteArray中自動地提供,并以不計數[size](qbytearray.html#size)( ) 。 QByteArray中提供了修飾的字節數據的以下基本功能:[append](qbytearray.html#append)( )[prepend](qbytearray.html#prepend)( )[insert](qbytearray.html#insert)( )[replace](qbytearray.html#replace)()和[remove](qbytearray.html#remove)( ) 。例如: ``` QByteArray x("and"); x.prepend("rock "); // x == "rock and" x.append(" roll"); // x == "rock and roll" x.replace(5, 3, "&"); // x == "rock & roll" ``` 該[replace](qbytearray.html#replace)()和[remove](qbytearray.html#remove)( )函數的前兩個參數是要開始擦除,并應被刪除的字節數的位置。 當你[append](qbytearray.html#append)()的數據到一個非空數組,該數組將被重新分配和新的數據復制到它。您可以通過調用避免這種行為[reserve](qbytearray.html#reserve)(),它預先分配一定數量的內存。您也可以撥打[capacity](qbytearray.html#capacity)( )來找出QByteArray中實際上有多少內存分配。追加到一個空數組數據不被復制。 一個常見的要求是從一個字節數組(的'\ n ',' \ T' ,'',等等)刪除空白字符。如果你想從一個QByteArray中的兩端刪除空白,使用[trimmed](qbytearray.html#trimmed)( ) 。如果你想從兩端刪除空白,并與字節數組中的單個空格字符替換多個連續的空格,使用[simplified](qbytearray.html#simplified)( ) 。 如果你想找到一個特定的字符或子串中所有出現在一個QByteArray中,使用[indexOf](qbytearray.html#indexOf)()或[lastIndexOf](qbytearray.html#lastIndexOf)( ) 。前者向前搜索從給定的索引位置,后者向后搜索開始。都返回字符或字符串的索引位置,如果他們找到它,否則,它們將返回-1 。例如,下面是一個典型的循環,找到一個特定的子字符串的所有匹配: ``` QByteArray ba("We must be <b>bold</b>, very <b>bold</b>"); int j = 0; while ((j = ba.indexOf("<b>", j)) != -1) { cout << "Found <b> tag at index position " << j << endl; ++j; } ``` 如果你只是想檢查一個QByteArray中是否包含特定的字符或子串,使用[contains](qbytearray.html#contains)( ) 。如果你想了解有多少次一個特定的字符或子發生在字節數組中,使用[count](qbytearray.html#count)( ) 。如果你想更換另一特定值的所有匹配,使用這兩個參數中的一個[replace](qbytearray.html#replace)( )重載。 QByteArrays可以使用重載運算符,如操作符\u003c ( ) ,操作符\u003c = ( ) ,運算符== ( )操作符\u003e = ( ) ,等進行比較。比較是完全基于字符的數值,是非常快的,但不是什么人期望的那樣。[QString.localeAwareCompare](qstring.html#localeAwareCompare)( )是用于排序用戶界面字符串一個更好的選擇。 由于歷史原因, QByteArray中一個空字節數組和一個空字節數組之間的區別。一_null_字節數組是使用QByteArray中的默認構造函數初始化或通過傳遞(為const char * )0給構造函數的字節數組。一個_empty_字節數組是任何字節數組大小為0 。一個空字節數組始終是空的,但一個空字節數組不一定空: ``` QByteArray().isNull(); // returns true QByteArray().isEmpty(); // returns true QByteArray("").isNull(); // returns false QByteArray("").isEmpty(); // returns true QByteArray("abc").isNull(); // returns false QByteArray("abc").isEmpty(); // returns false ``` 之外的全部功能[isNull](qbytearray.html#isNull)( )把空字節數組一樣的空字節數組。例如,[data](qbytearray.html#data)( )返回一個指向一個'\ 0 '字符為一個空字節數組(_not_一個空指針) ,和[QByteArray](qbytearray.html#QByteArray)( )比較等于QByteArray中( “”) 。我們建議您始終使用[isEmpty](qbytearray.html#isEmpty)()和避免[isNull](qbytearray.html#isNull)( ) 。 ### Notes on Locale #### Number-String Conversions 該數值數據類型和字符串之間進行轉換函數在C語言環境進行,而不管用戶的區域設置。使用[QString](qstring.html)以數字和字符串之間進行區域設置的格式轉換。 #### 8-bit Character Comparisons 在QByteArray中,其性格和大寫和小寫的概念是大于或小于另一個特點是與當前位置有關。這會影響支持不區分大小寫的選項或比較或小寫或大寫的參數的函數。不區分大小寫的操作和比較將是準確的,如果兩個字符串只包含ASCII字符。 (如果`$LC_CTYPE`設置,大多數Unix系統做“正確的事” 。 )功能,這會影響包括:[contains](qbytearray.html#contains)( )[indexOf](qbytearray.html#indexOf)( )[lastIndexOf](qbytearray.html#lastIndexOf)( )操作符\u003c ( ) ,操作符\u003c = ( ) ,操作者\u003e ( ) ,運算符\u003e = ( ) ,[toLower](qbytearray.html#toLower)()和[toUpper](qbytearray.html#toUpper)( ) 。 這個問題并不適用于將QString因為它們代表使用Unicode字符。 * * * ## Method Documentation ``` QByteArray.__init__ (self) ``` 構造一個空字節數組。 **See also** [isEmpty](qbytearray.html#isEmpty)( ) 。 ``` QByteArray.__init__ (self, int?size, str?c) ``` 構造一個字符串初始化一個字節數組_str_。 [QByteArray](qbytearray.html)使得字符串數據的深層副本。 ``` QByteArray.__init__ (self, QByteArray?a) ``` 構造一個包含第一個字節數組_size_數組的字節_data_。 If _data_是0 ,一個空字節數組構造。 [QByteArray](qbytearray.html)使得字符串數據的深層副本。 **See also** [fromRawData](qbytearray.html#fromRawData)( ) 。 ``` QByteArray QByteArray.append (self, QByteArray?a) ``` [ 附加的字節數組_ba_到這個字節數組的末尾。 例如: ](qbytearray.html) ``` QByteArray x("free"); [QByteArray](qbytearray.html) y("dom"); x.append(y); // x == "freedom" ``` 這是相同的插入物([size](qbytearray.html#size)( )_ba_) 。 注意:[QByteArray](qbytearray.html)是[implicitly shared](index.htm#implicitly-shared)類。因此,如果_this_是一個空[QByteArray](qbytearray.html),然后_this_只是在共享中的數據_ba_。在這種情況下,不復制數據的操作后,取[constant time](index.htm#constant-time)。如果共享的實例被改性時,其將被復制(復制寫入時) ,取[linear time](index.htm#linear-time)。 If _this_是不是空[QByteArray](qbytearray.html),數據的深層副本中進行,取[linear time](index.htm#linear-time)。 此操作通常不會從分配開銷受到影響,因為[QByteArray](qbytearray.html)預先分配額外的空間,在數據的末尾,這樣它可以生長而不重新分配為每個附加的操作。 **See also** [operator+=](qbytearray.html#operator-2b-eq)( )[prepend](qbytearray.html#prepend)()和[insert](qbytearray.html#insert)( ) 。 ``` QByteArray QByteArray.append (self, QString?s) ``` [ 這是一個重載函數。 ](qbytearray.html) [附加字符串_str_這個字節數組。在Unicode數據使用轉換為8位字符](qbytearray.html)[QString.toAscii](qstring.html#toAscii)( ) 。 如果[QString](qstring.html)包含非ASCII Unicode字符,使用此功能可能會導致信息丟失。您可以通過定義關閉此功能`QT_NO_CAST_TO_ASCII`當您編譯您的應用程序。然后,您需要調用[QString.toAscii](qstring.html#toAscii)( )(或[QString.toLatin1](qstring.html#toLatin1)()或[QString.toUtf8](qstring.html#toUtf8)()或[QString.toLocal8Bit](qstring.html#toLocal8Bit)( ) )明確,如果你想將數據轉換為`const char *`。 ``` str QByteArray.at (self, int?i) ``` 返回字符的索引位置_i_在字節數組。 _i_必須是字節數組中的一個有效的索引位置(即0 \u003c =_i_\u003c[size](qbytearray.html#size)())。 **See also** [operator[]](qbytearray.html#operator-5b-5d)( ) 。 ``` int QByteArray.capacity (self) ``` 返回一個可存儲在字節數組中,而不必強制重新分配的最大字節數。 此函數的唯一目的是提供微調的手段[QByteArray](qbytearray.html)的內存使用情況。一般情況下,你很少會需要調用這個函數。如果你想知道有多少字節在字節數組,調用[size](qbytearray.html#size)( ) 。 **See also** [reserve](qbytearray.html#reserve)()和[squeeze](qbytearray.html#squeeze)( ) 。 ``` QByteArray.chop (self, int?n) ``` 移除_n_從字節數組的末尾字節。 If _n_大于[size](qbytearray.html#size)( ) ,結果是一個空字節數組。 例如: ``` [QByteArray](qbytearray.html) ba("STARTTLS\r\n"); ba.chop(2); // ba == "STARTTLS" ``` **See also** [truncate](qbytearray.html#truncate)( )[resize](qbytearray.html#resize)()和[left](qbytearray.html#left)( ) 。 ``` QByteArray.clear (self) ``` 清除字節數組的內容,使得它為空。 **See also** [resize](qbytearray.html#resize)()和[isEmpty](qbytearray.html#isEmpty)( ) 。 ``` bool QByteArray.contains (self, QByteArray?a) ``` 如果字節數組包含字節數組的出現,則返回True_ba_否則返回False 。 **See also** [indexOf](qbytearray.html#indexOf)()和[count](qbytearray.html#count)( ) 。 ``` int QByteArray.count (self, QByteArray?a) ``` 返回(可能重疊)出現字節數組數_ba_在這個字節數組。 **See also** [contains](qbytearray.html#contains)()和[indexOf](qbytearray.html#indexOf)( ) 。 ``` int QByteArray.count (self) ``` 這是一個重載函數。 返回(可能重疊的)串出現的次數_str_在字節數組。 ``` str QByteArray.data (self) ``` 返回一個指針,指向存儲在字節數組中的數據。該指針可用于訪問和修改構成該陣列的字節數。的數據是'\ 0'終止,即字節在返回的字符串的數目是[size](qbytearray.html#size)( ) + 1的' \ 0 '終止。 例如: ``` [QByteArray](qbytearray.html) ba("Hello world"); char *data = ba.data(); while (*data) { cout << "[" << *data << "]" << endl; ++data; } ``` 指針仍然有效,只要將字節數組是不是重新分配或銷毀。對于只讀訪問,[constData](qbytearray.html#constData)( )快,因為它不會導致一個[deep copy](index.htm#deep-copy)發生。 這個函數只是有用的一個字節數組傳遞給一個接受一個函數`const char *`。 下面的示例使字符*由數據()返回的副本,但它會破壞堆并導致崩潰,因為它沒有在最后分配的' \ 0 '一個字節: ``` [QString](qstring.html) tmp = "test"; [QByteArray](qbytearray.html) text = tmp.toLocal8Bit(); char *data = new char[text.size()] strcpy(data, text.data()); delete [] data; ``` 這個分配的正確的空間量: ``` [QString](qstring.html) tmp = "test"; [QByteArray](qbytearray.html) text = tmp.toLocal8Bit(); char *data = new char[text.size() + 1] strcpy(data, text.data()); delete [] data; ``` 注意:[QByteArray](qbytearray.html)可以存儲任何字節值包括'\ 0的,但大部分的功能,采取`char *`參數假設數據在第一個'\ 0 ',他們遇到的結束。 **See also** [constData](qbytearray.html#constData)()和[operator[]](qbytearray.html#operator-5b-5d)( ) 。 ``` bool QByteArray.endsWith (self, QByteArray?a) ``` 如果該字節數組byte數組結尾,則返回True_ba_否則返回False 。 例如: ``` [QByteArray](qbytearray.html) url("http://qt.nokia.com/index.html"); if (url.endsWith(".html")) ... ``` **See also** [startsWith](qbytearray.html#startsWith)()和[right](qbytearray.html#right)( ) 。 ``` QByteArray QByteArray.fill (self, str?ch, int?size?=?-1) ``` [ 設置每個字節的字節數組字符_ch_。如果_size_是從-1 (默認值)不同,字節數組大小調整大小_size_事前。 例如: ](qbytearray.html) ``` QByteArray ba("Istambul"); ba.fill('o'); // ba == "oooooooo" ba.fill('X', 2); // ba == "XX" ``` **See also** [resize](qbytearray.html#resize)( ) 。 ``` QByteArray QByteArray.fromBase64 (QByteArray?base64) ``` [ 返回Base64數組的一個副本解碼_base64_。輸入不進行有效性檢查,在輸入無效字符被跳過,使解碼過程繼續進行后續字符。 例如: ](qbytearray.html) ``` QByteArray text = [QByteArray](qbytearray.html).fromBase64("UXQgaXMgZ3JlYXQh"); text.data(); // returns "Qt is great!" ``` 用于解碼Base64編碼數據的算法中所定義[RFC 2045](http://www.rfc-editor.org/rfc/rfc2045.txt)。 **See also** [toBase64](qbytearray.html#toBase64)( ) 。 ``` QByteArray QByteArray.fromHex (QByteArray?hexEncoded) ``` [ 返回十六進制編碼數組的副本解碼_hexEncoded_。輸入不進行有效性檢查,在輸入無效字符被跳過,使解碼過程繼續進行后續字符。 例如: ](qbytearray.html) ``` QByteArray text = [QByteArray](qbytearray.html).fromHex("517420697320677265617421"); text.data(); // returns "Qt is great!" ``` **See also** [toHex](qbytearray.html#toHex)( ) 。 ``` QByteArray QByteArray.fromPercentEncoding (QByteArray?input, str?percent?=?'%') ``` [](qbytearray.html) [返回的URI / URL樣式的百分比編碼解碼副本_input_。該_percent_參數允許你替換“%”字符為另一個(例如, '](qbytearray.html)[_](index.html)'或' =') 。 例如: ``` [QByteArray](qbytearray.html) text = [QByteArray](qbytearray.html).fromPercentEncoding("Qt%20is%20great%33"); text.data(); // returns "Qt is great!" ``` 此功能被引入Qt的4.4 。 **See also** [toPercentEncoding](qbytearray.html#toPercentEncoding)()和[QUrl.fromPercentEncoding](qurl.html#fromPercentEncoding)( ) 。 ``` QByteArray QByteArray.fromRawData (str) ``` [](qbytearray.html) [構造一個](qbytearray.html)[QByteArray](qbytearray.html)使用該第一_size_的字節_data_數組。該字節_not_復制。該[QByteArray](qbytearray.html)將包含_data_指針。調用者保證_data_也不會被刪除或修改,只要這[QByteArray](qbytearray.html)并且沒有被修改的任何拷貝存在。換言之,因為[QByteArray](qbytearray.html)是[implicitly shared](index.htm#implicitly-shared)類,并通過這個函數返回的實例包含_data_指針,調用者不得刪除_data_或直接修改它只要返回[QByteArray](qbytearray.html)和任何副本存在。但是,[QByteArray](qbytearray.html)不采取所有權_data_的,所以[QByteArray](qbytearray.html)析構函數永遠不會刪除原_data_時,即使最后[QByteArray](qbytearray.html)指_data_被破壞。 隨后試圖修改返回的內容[QByteArray](qbytearray.html)或者從它所做的任何拷貝將導致其創建的一個深層副本_data_在做修改前的數組。這確保了生_data_數組本身將永遠不會被修改[QByteArray](qbytearray.html)。 下面是如何使用一個讀取數據的例子[QDataStream](qdatastream.html)在內存中的原始數據,而無需對原始數據復制到一個[QByteArray](qbytearray.html): ``` static const char mydata[] = { 0x00, 0x00, 0x03, 0x84, 0x78, 0x9c, 0x3b, 0x76, 0xec, 0x18, 0xc3, 0x31, 0x0a, 0xf1, 0xcc, 0x99, ... 0x6d, 0x5b }; [QByteArray](qbytearray.html) data = [QByteArray](qbytearray.html).fromRawData(mydata, sizeof(mydata)); [QDataStream](qdatastream.html) in(&data, [QIODevice](qiodevice.html).ReadOnly); ... ``` **Warning:**)與fromRawData (創建的字節數組是_not_null結尾,除非原始數據包含0字符位置_size_。雖然這不要緊,[QDataStream](qdatastream.html)或相似的功能[indexOf](qbytearray.html#indexOf)( ) ,傳遞字節數組的函數接受一個`const char *`預期為'\ 0'末端都將失敗。 **See also** [setRawData](qbytearray.html#setRawData)( )[data](qbytearray.html#data)()和[constData](qbytearray.html#constData)( ) 。 ``` int QByteArray.indexOf (self, QByteArray?ba, int?from?=?0) ``` 返回字節數組中第一次出現的索引位置_ba_在這個字節數組,向前搜索的索引位置_from_。返回-1,如果_ba_找不到。 例如: ``` [QByteArray](qbytearray.html) x("sticky question"); [QByteArray](qbytearray.html) y("sti"); x.indexOf(y); // returns 0 x.indexOf(y, 1); // returns 10 x.indexOf(y, 10); // returns 10 x.indexOf(y, 11); // returns -1 ``` **See also** [lastIndexOf](qbytearray.html#lastIndexOf)( )[contains](qbytearray.html#contains)()和[count](qbytearray.html#count)( ) 。 ``` int QByteArray.indexOf (self, QString?str, int?from?=?0) ``` 這是一個重載函數。 返回字符串中第一次出現的索引位置_str_字節數組中,尋找著從索引位置_from_。返回-1,如果_str_找不到。 在Unicode數據使用轉換為8位字符[QString.toAscii](qstring.html#toAscii)( ) 。 如果[QString](qstring.html)包含非ASCII Unicode字符,使用此功能可能會導致信息丟失。您可以通過定義關閉此功能`QT_NO_CAST_TO_ASCII`當您編譯您的應用程序。然后,您需要調用[QString.toAscii](qstring.html#toAscii)( )(或[QString.toLatin1](qstring.html#toLatin1)()或[QString.toUtf8](qstring.html#toUtf8)()或[QString.toLocal8Bit](qstring.html#toLocal8Bit)( ) )明確,如果你想將數據轉換為`const char *`。 ``` QByteArray QByteArray.insert (self, int?i, QByteArray?a) ``` [ 插入的字節數組_ba_在索引位置_i_并返回一個引用到這個字節數組。 例如: ](qbytearray.html) ``` QByteArray ba("Meal"); ba.insert(1, [QByteArray](qbytearray.html)("ontr")); // ba == "Montreal" ``` **See also** [append](qbytearray.html#append)( )[prepend](qbytearray.html#prepend)( )[replace](qbytearray.html#replace)()和[remove](qbytearray.html#remove)( ) 。 ``` QByteArray QByteArray.insert (self, int?i, QString?s) ``` [ 這是一個重載函數。 ](qbytearray.html) [插入字符串_str_在索引位置_i_在字節數組。在Unicode數據使用轉換為8位字符](qbytearray.html)[QString.toAscii](qstring.html#toAscii)( ) 。 If _i_大于[size](qbytearray.html#size)() ,該陣列是第一,采用擴展[resize](qbytearray.html#resize)( ) 。 如果[QString](qstring.html)包含非ASCII Unicode字符,使用此功能可能會導致信息丟失。您可以通過定義關閉此功能`QT_NO_CAST_TO_ASCII`當您編譯您的應用程序。然后,您需要調用[QString.toAscii](qstring.html#toAscii)( )(或[QString.toLatin1](qstring.html#toLatin1)()或[QString.toUtf8](qstring.html#toUtf8)()或[QString.toLocal8Bit](qstring.html#toLocal8Bit)( ) )明確,如果你想將數據轉換為`const char *`。 ``` bool QByteArray.isEmpty (self) ``` 返回True如果字節數組的大小為0 ,否則返回False 。 例如: ``` [QByteArray](qbytearray.html)().isEmpty(); // returns true [QByteArray](qbytearray.html)("").isEmpty(); // returns true [QByteArray](qbytearray.html)("abc").isEmpty(); // returns false ``` **See also** [size](qbytearray.html#size)( ) 。 ``` bool QByteArray.isNull (self) ``` 返回True如果該字節數組為null ,否則返回False 。 例如: ``` [QByteArray](qbytearray.html)().isNull(); // returns true [QByteArray](qbytearray.html)("").isNull(); // returns false [QByteArray](qbytearray.html)("abc").isNull(); // returns false ``` Qt后,由于歷史原因,空字節數組和空字節數組之間的區別。對于大多數應用來說,重要的是一個字節數組中是否包含任何數據,這可以通過使用來確定[isEmpty](qbytearray.html#isEmpty)( ) 。 **See also** [isEmpty](qbytearray.html#isEmpty)( ) 。 ``` int QByteArray.lastIndexOf (self, QByteArray?ba, int?from?=?-1) ``` 返回字節數組中最后一次出現的索引位置_ba_在這個字節數組,從索引位置向后搜索_from_。如果_from_為-1 (默認值) ,該搜索從最后一個字節。返回-1,如果_ba_找不到。 例如: ``` [QByteArray](qbytearray.html) x("crazy azimuths"); [QByteArray](qbytearray.html) y("az"); x.lastIndexOf(y); // returns 6 x.lastIndexOf(y, 6); // returns 6 x.lastIndexOf(y, 5); // returns 2 x.lastIndexOf(y, 1); // returns -1 ``` **See also** [indexOf](qbytearray.html#indexOf)( )[contains](qbytearray.html#contains)()和[count](qbytearray.html#count)( ) 。 ``` int QByteArray.lastIndexOf (self, QString?str, int?from?=?-1) ``` 這是一個重載函數。 返回字符串中最后一次出現的索引位置_str_字節數組中,從索引位置向后搜索_from_。如果_from_為-1 (默認值) ,開始搜索在最后([size](qbytearray.html#size)( ) - 1 )字節。返回-1,如果_str_找不到。 在Unicode數據使用轉換為8位字符[QString.toAscii](qstring.html#toAscii)( ) 。 如果[QString](qstring.html)包含非ASCII Unicode字符,使用此功能可能會導致信息丟失。您可以通過定義關閉此功能`QT_NO_CAST_TO_ASCII`當您編譯您的應用程序。然后,您需要調用[QString.toAscii](qstring.html#toAscii)( )(或[QString.toLatin1](qstring.html#toLatin1)()或[QString.toUtf8](qstring.html#toUtf8)()或[QString.toLocal8Bit](qstring.html#toLocal8Bit)( ) )明確,如果你想將數據轉換為`const char *`。 ``` QByteArray QByteArray.left (self, int?len) ``` [ 返回包含最左邊的字節數組_len_這個字節數組的字節。 ](qbytearray.html) [如果整個字節數組返回_len_大于](qbytearray.html)[size](qbytearray.html#size)( ) 。 例如: ``` [QByteArray](qbytearray.html) x("Pineapple"); [QByteArray](qbytearray.html) y = x.left(4); // y == "Pine" ``` **See also** [right](qbytearray.html#right)( )[mid](qbytearray.html#mid)( )[startsWith](qbytearray.html#startsWith)()和[truncate](qbytearray.html#truncate)( ) 。 ``` QByteArray QByteArray.leftJustified (self, int?width, str?fill?=?' ', bool?truncate?=?False) ``` [ 返回大小的字節數組_width_包含由該填充字節數組_fill_字符。 ](qbytearray.html) [If _truncate_是假的而](qbytearray.html)[size](qbytearray.html#size)字節數組的( )超過_width_,則返回的字節數組是該字節數組的一個副本。 If _truncate_是真實的[size](qbytearray.html#size)字節數組的( )超過_width_,然后在后的位置的字節數組的副本的任何字節_width_被刪除,并且該副本被返回。 例如: ``` [QByteArray](qbytearray.html) x("apple"); [QByteArray](qbytearray.html) y = x.leftJustified(8, '.'); // y == "apple..." ``` **See also** [rightJustified](qbytearray.html#rightJustified)( ) 。 ``` int QByteArray.length (self) ``` 同[size](qbytearray.html#size)( ) 。 ``` QByteArray QByteArray.mid (self, int?pos, int?length?=?-1) ``` [ 返回一個包含一個字節數組_len_從這個字節數組,起始于位置_pos_。 ](qbytearray.html) [If _len_為-1 (默認) ,或_pos_+_len_\u003e =](qbytearray.html)[size](qbytearray.html#size)( ) ,返回一個包含所有字節起始于位置的字節數組_pos_直到字節數組的結尾。 例如: ``` [QByteArray](qbytearray.html) x("Five pineapples"); [QByteArray](qbytearray.html) y = x.mid(5, 4); // y == "pine" [QByteArray](qbytearray.html) z = x.mid(5); // z == "pineapples" ``` **See also** [left](qbytearray.html#left)()和[right](qbytearray.html#right)( ) 。 ``` QByteArray QByteArray.number (int?n, int?base?=?10) ``` [ 返回一個包含字符串相等的數目的字節數組_n_基地_base_(默認為10 ) 。該_base_可以是2到36之間的任意值。 例如: ](qbytearray.html) ``` int n = 63;QByteArray.number(n); // returns "63" [QByteArray](qbytearray.html).number(n, 16); // returns "3f" [QByteArray](qbytearray.html).number(n, 16).toUpper(); // returns "3F" ``` **Note:**數字的格式不本地化,缺省的C語言環境,不論使用者的語言環境中使用。 **See also** [setNum](qbytearray.html#setNum)()和[toInt](qbytearray.html#toInt)( ) 。 ``` QByteArray QByteArray.number (float?n, str?format?=?'g', int?precision?=?6) ``` [ 這是一個重載函數。 ](qbytearray.html) [**See also**](qbytearray.html) [toUInt](qbytearray.html#toUInt)( ) 。 ``` QByteArray QByteArray.number (int?n, int?base?=?10) ``` [ 這是一個重載函數。 ](qbytearray.html) [**See also**](qbytearray.html) [toLongLong](qbytearray.html#toLongLong)( ) 。 ``` QByteArray QByteArray.number (int?n, int?base?=?10) ``` [ 這是一個重載函數。 ](qbytearray.html) [**See also**](qbytearray.html) [toULongLong](qbytearray.html#toULongLong)( ) 。 ``` QByteArray QByteArray.prepend (self, QByteArray?a) ``` [ 預先考慮字節數組_ba_這個字節數組并返回一個引用到這個字節數組。 例如: ](qbytearray.html) ``` QByteArray x("ship"); [QByteArray](qbytearray.html) y("air"); x.prepend(y); // x == "airship" ``` 這是相同的插入件(0,_ba_) 。 注意:[QByteArray](qbytearray.html)是[implicitly shared](index.htm#implicitly-shared)類。因此,如果_this_是一個空[QByteArray](qbytearray.html),然后_this_只是在共享中的數據_ba_。在這種情況下,不復制數據的操作后,取[constant time](index.htm#constant-time)。如果共享的實例被改性時,其將被復制(復制寫入時) ,取[linear time](index.htm#linear-time)。 If _this_是不是空[QByteArray](qbytearray.html),數據的深層副本中進行,取[linear time](index.htm#linear-time)。 **See also** [append](qbytearray.html#append)()和[insert](qbytearray.html#insert)( ) 。 ``` QByteArray.push_back (self, QByteArray?a) ``` 此功能提供了STL的兼容性。它相當于追加(_other_) 。 ``` QByteArray.push_front (self, QByteArray?a) ``` 此功能提供了STL的兼容性。它相當于前置(_other_) 。 ``` QByteArray QByteArray.remove (self, int?index, int?len) ``` [ 移除_len_從字節數組,起始索引位置_pos_,并返回一個引用數組。 If _pos_超出范圍,沒有任何反應。如果_pos_是有效的,但_pos_+_len_比數組的大小較大時,陣列處被截斷位置_pos_。 例如: ](qbytearray.html) ``` QByteArray ba("Montreal"); ba.remove(1, 4); // ba == "Meal" ``` **See also** [insert](qbytearray.html#insert)()和[replace](qbytearray.html#replace)( ) 。 ``` QByteArray QByteArray.repeated (self, int?times) ``` [ 返回此字節數組的副本重復指定次數_times_。 If _times_小于1 ,則返回一個空字節數組。 例如: ](qbytearray.html) ``` QByteArray ba("ab"); ba.repeated(4); // returns "abababab" ``` 此功能被引入Qt的4.5 。 ``` QByteArray QByteArray.replace (self, int?index, int?len, QByteArray?s) ``` [ 替換_len_從索引位置字節_pos_與字節數組_after_,并返回一個引用到這個字節數組。 例如: ](qbytearray.html) ``` QByteArray x("Say yes!"); [QByteArray](qbytearray.html) y("no"); x.replace(4, 3, y); // x == "Say no!" ``` **See also** [insert](qbytearray.html#insert)()和[remove](qbytearray.html#remove)( ) 。 ``` QByteArray QByteArray.replace (self, QByteArray?before, QByteArray?after) ``` [ 這是一個重載函數。 替換_len_從索引位置字節_pos_以零結尾的字符串_after_。 注意:這個可以改變字節數組的長度。 ](qbytearray.html) ``` QByteArray QByteArray.replace (self, QString?before, QByteArray?after) ``` [ 這是一個重載函數。 替換_len_從索引位置字節_pos_同_alen_從字符串字節_after_。_after_允許有'\ 0 '字符。 此功能被引入Qt的4.7 。 ``` QByteArray.reserve (self, int?size) ``` ](qbytearray.html) [嘗試分配內存,至少_size_字節。如果你事先知道將字節數組將有多大的話,你可以調用這個函數,如果你調用](qbytearray.html)[resize](qbytearray.html#resize)( )通常你很可能會獲得更好的性能。如果_size_是低估,會發生最壞的是,[QByteArray](qbytearray.html)會有點慢。 此函數的唯一目的是提供微調的手段[QByteArray](qbytearray.html)的內存使用情況。一般情況下,你很少會需要調用這個函數。如果你想改變的字節數組的大小,請致電[resize](qbytearray.html#resize)( ) 。 **See also** [squeeze](qbytearray.html#squeeze)()和[capacity](qbytearray.html#capacity)( ) 。 ``` QByteArray.resize (self, int?size) ``` 設置字節數組的大小_size_字節。 If _size_大于該電流的大小,字節數組被擴展以使其_size_與末尾添加額外的字節字節。新的字節被初始化。 If _size_小于該電流的大小,字節被從端部除去。 **See also** [size](qbytearray.html#size)()和[truncate](qbytearray.html#truncate)( ) 。 ``` QByteArray QByteArray.right (self, int?len) ``` [ 返回包含最右邊的字節數組_len_這個字節數組的字節。 ](qbytearray.html) [如果整個字節數組返回_len_大于](qbytearray.html)[size](qbytearray.html#size)( ) 。 例如: ``` [QByteArray](qbytearray.html) x("Pineapple"); [QByteArray](qbytearray.html) y = x.right(5); // y == "apple" ``` **See also** [endsWith](qbytearray.html#endsWith)( )[left](qbytearray.html#left)()和[mid](qbytearray.html#mid)( ) 。 ``` QByteArray QByteArray.rightJustified (self, int?width, str?fill?=?' ', bool?truncate?=?False) ``` [ 返回大小的字節數組_width_包含_fill_字符后跟這個字節數組。 If _truncate_是假的字節數組的大小超過_width_,則返回的字節數組是該字節數組的一個副本。 If _truncate_是真實的字節數組的大小超過_width_,然后將得到的字節數組被截斷位置_width_。 例如: ](qbytearray.html) ``` QByteArray x("apple"); [QByteArray](qbytearray.html) y = x.rightJustified(8, '.'); // y == "...apple" ``` **See also** [leftJustified](qbytearray.html#leftJustified)( ) 。 ``` QByteArray QByteArray.setNum (self, int?n, int?base?=?10) ``` [ 設置字節數組的印刷價值_n_在基地_base_(默認為10 ),并返回一個引用到的字節數組。該_base_可以是2到36之間的任意值。 例如: ](qbytearray.html) ``` QByteArray ba; int n = 63; ba.setNum(n); // ba == "63" ba.setNum(n, 16); // ba == "3f" ``` **Note:**數字的格式不本地化,缺省的C語言環境,不論使用者的語言環境中使用。 **See also** [number](qbytearray.html#number)()和[toInt](qbytearray.html#toInt)( ) 。 ``` QByteArray QByteArray.setNum (self, float?n, str?format?=?'g', int?precision?=?6) ``` [ 這是一個重載函數。 ](qbytearray.html) [**See also**](qbytearray.html) [toUInt](qbytearray.html#toUInt)( ) 。 ``` QByteArray QByteArray.setNum (self, int?n, int?base?=?10) ``` [ 這是一個重載函數。 ](qbytearray.html) [**See also**](qbytearray.html) [toShort](qbytearray.html#toShort)( ) 。 ``` QByteArray QByteArray.setNum (self, int?n, int?base?=?10) ``` [ 這是一個重載函數。 ](qbytearray.html) [**See also**](qbytearray.html) [toUShort](qbytearray.html#toUShort)( ) 。 ``` QByteArray QByteArray.simplified (self) ``` [ 返回一個字節數組,它已經從空白開始和結束時去除,并具有內部的空格用一個空格代替每個序列。 空白單元,對標準C + +的使用isspace ( )函數返回True的任何字符。這包括ASCII字符'\ T' ,為'\ n ',' \ V' , '\ F' , ' \ r '和' “ 。 例如: ](qbytearray.html) ``` QByteArray ba(" lots\t of\nwhitespace\r\n "); ba = ba.simplified(); // ba == "lots of whitespace"; ``` **See also** [trimmed](qbytearray.html#trimmed)( ) 。 ``` int QByteArray.size (self) ``` 返回此字節數組的字節數。 字節數組中的最后一個字節是在位置的大小( ) - 1 。另外,[QByteArray](qbytearray.html)確保在位置大小的字節( )總是'\ 0' ,這樣就可以使用的返回值[data](qbytearray.html#data)()和[constData](qbytearray.html#constData)()作為參數傳遞給該期待'\ 0'結尾的字符串函數。如果[QByteArray](qbytearray.html)對象是從創建[raw data](qbytearray.html#fromRawData)這不包括結尾的空終止字符,然后[QByteArray](qbytearray.html)不添加它automaticall除非[deep copy](index.htm#deep-copy)被創建。 例如: ``` [QByteArray](qbytearray.html) ba("Hello"); int n = ba.size(); // n == 5 ba.data()[0]; // returns 'H' ba.data()[4]; // returns 'o' ba.data()[5]; // returns '\0' ``` **See also** [isEmpty](qbytearray.html#isEmpty)()和[resize](qbytearray.html#resize)( ) 。 ``` list-of-QByteArray QByteArray.split (self, str?sep) ``` 拆分字節數組轉換成子陣的地方_sep_發生,并返回這些陣列的列表。如果_sep_不匹配的字節數組,分割任何地方( )返回一個包含此字節數組中的單個元素的列表。 ``` QByteArray.squeeze (self) ``` 釋放任何內存不需要存儲陣列的數據。 此函數的唯一目的是提供微調的手段[QByteArray](qbytearray.html)的內存使用情況。一般情況下,你很少會需要調用這個函數。 **See also** [reserve](qbytearray.html#reserve)()和[capacity](qbytearray.html#capacity)( ) 。 ``` bool QByteArray.startsWith (self, QByteArray?a) ``` 如果這個字節數組開頭的字節數組,則返回True_ba_否則返回False 。 例如: ``` [QByteArray](qbytearray.html) url("ftp://ftp.qt.nokia.com/"); if (url.startsWith("ftp:")) ... ``` **See also** [endsWith](qbytearray.html#endsWith)() and [left](qbytearray.html#left)(). ``` QByteArray.swap (self, QByteArray?other) ``` 掉期的字節數組_other_與此字節數組。這個操作是非常快的,而且永遠不會。 此功能被引入Qt的4.8 。 ``` QByteArray QByteArray.toBase64 (self) ``` [ 返回字節數組的副本,按Base64編碼。 ](qbytearray.html) ``` QByteArray text("Qt is great!"); text.toBase64(); // returns "UXQgaXMgZ3JlYXQh" ``` 使用Base64編碼的數據進行編碼的算法定義中[RFC 2045](http://www.rfc-editor.org/rfc/rfc2045.txt)。 **See also** [fromBase64](qbytearray.html#fromBase64)( ) 。 ``` (float, bool?ok) QByteArray.toDouble (self) ``` 返回字節數組轉換為`double`值。 如果轉換失敗,則返回0.0 。 If _ok_不為0 :如果發生轉換錯誤, *_ok_設置為False ,否則*_ok_設置為True 。 ``` [QByteArray](qbytearray.html) string("1234.56"); double a = string.toDouble(); // a == 1234.56 ``` **Note:**在默認的C語言環境下進行數字轉換,而不論用戶的語言環境。 **See also** [number](qbytearray.html#number)( ) 。 ``` (float, bool?ok) QByteArray.toFloat (self) ``` 返回字節數組轉換為`float`值。 如果轉換失敗,則返回0.0 。 If _ok_不為0 :如果發生轉換錯誤, *_ok_設置為False ,否則*_ok_設置為True 。 **Note:**在默認的C語言環境下進行數字轉換,而不論用戶的語言環境。 **See also** [number](qbytearray.html#number)( ) 。 ``` QByteArray QByteArray.toHex (self) ``` [ 返回字節數組的十六進制編碼副本。十六進制編碼使用數字0-9和字母AF 。 ](qbytearray.html) [**See also**](qbytearray.html) [fromHex](qbytearray.html#fromHex)( ) 。 ``` (int, bool?ok) QByteArray.toInt (self, int?base?=?10) ``` 返回字節數組轉換為`int`使用基_base_,它默認為10 ,并且必須是2和36 ,或0之間。 If _base_為0時,該基地是使用以下規則自動確定:如果字節數組開始以“0x” ,它被假定為十六進制的,如果它以“ 0 ”時,它被假定為八進制,否則它被假定為是小數。 返回0,如果轉換失敗。 If _ok_不為0 :如果發生轉換錯誤, *_ok_設置為False ,否則*_ok_設置為True 。 ``` [QByteArray](qbytearray.html) str("FF"); bool ok; int hex = str.toInt(&ok, 16); // hex == 255, ok == true int dec = str.toInt(&ok, 10); // dec == 0, ok == false ``` **Note:**在默認的C語言環境下進行數字轉換,而不論用戶的語言環境。 **See also** [number](qbytearray.html#number)( ) 。 ``` (int, bool?ok) QByteArray.toLong (self, int?base?=?10) ``` 返回字節數組轉換為`long`INT使用基_base_,它默認為10 ,并且必須是2和36 ,或0之間。 If _base_為0時,該基地是使用以下規則自動確定:如果字節數組開始以“0x” ,它被假定為十六進制的,如果它以“ 0 ”時,它被假定為八進制,否則它被假定為是小數。 返回0,如果轉換失敗。 If _ok_不為0 :如果發生轉換錯誤, *_ok_設置為False ,否則*_ok_設置為True 。 ``` [QByteArray](qbytearray.html) str("FF"); bool ok; long hex = str.toLong(&ok, 16); // hex == 255, ok == true long dec = str.toLong(&ok, 10); // dec == 0, ok == false ``` **Note:**在默認的C語言環境下進行數字轉換,而不論用戶的語言環境。 這個函數是Qt 4.1中引入。 **See also** [number](qbytearray.html#number)( ) 。 ``` (int, bool?ok) QByteArray.toLongLong (self, int?base?=?10) ``` 返回字節數組轉換為`long long`使用基_base_,它默認為10 ,并且必須是2和36 ,或0之間。 If _base_為0時,該基地是使用以下規則自動確定:如果字節數組開始以“0x” ,它被假定為十六進制的,如果它以“ 0 ”時,它被假定為八進制,否則它被假定為是小數。 返回0,如果轉換失敗。 If _ok_不為0 :如果發生轉換錯誤, *_ok_設置為False ,否則*_ok_設置為True 。 **Note:**在默認的C語言環境下進行數字轉換,而不論用戶的語言環境。 **See also** [number](qbytearray.html#number)( ) 。 ``` QByteArray QByteArray.toLower (self) ``` [ 返回字節數組的小寫副本。從ByteArray中被解釋為Latin-1的編碼字符串。 例如: ](qbytearray.html) ``` QByteArray x("Qt by NOKIA"); [QByteArray](qbytearray.html) y = x.toLower(); // y == "qt by nokia" ``` **See also** [toUpper](qbytearray.html#toUpper)()和[8-bit Character Comparisons](qbytearray.html#8-bit-character-comparisons)。 ``` QByteArray QByteArray.toPercentEncoding (self, QByteArray?exclude?=?QByteArray(), QByteArray?include?=?QByteArray(), str?percent?=?'%') ``` [ 返回此字節數組的一個URI / URL樣式的百分比編碼副本。該_percent_參數允許您復蓋默認的“%”字符為另一個。 默認情況下,此功能將編碼不屬于下列之一的所有字符: ](qbytearray.html) [ALPHA( “a”到“z”的和“A”到“Z” ) /數字(0到9)/ “ - ” /“。 ” / “](qbytearray.html)[_](index.html)“/” ?“ 為了防止字符被編碼它們傳遞給_exclude_。要強制字符進行編碼它們傳遞給_include_。該_percent_字符總是編碼。 例如: ``` [QByteArray](qbytearray.html) text = "{a fishy string?}"; [QByteArray](qbytearray.html) ba = text.toPercentEncoding("{}", "s"); qDebug(ba.constData()); // prints "{a fi%73hy %73tring%3F}" ``` 十六進制編碼使用數字0-9以及大寫字母AF 。 此功能被引入Qt的4.4 。 **See also** [fromPercentEncoding](qbytearray.html#fromPercentEncoding)()和[QUrl.toPercentEncoding](qurl.html#toPercentEncoding)( ) 。 ``` (int, bool?ok) QByteArray.toShort (self, int?base?=?10) ``` 返回字節數組轉換為`short`使用基_base_,它默認為10 ,并且必須是2和36 ,或0之間。 If _base_為0時,該基地是使用以下規則自動確定:如果字節數組開始以“0x” ,它被假定為十六進制的,如果它以“ 0 ”時,它被假定為八進制,否則它被假定為是小數。 返回0,如果轉換失敗。 If _ok_不為0 :如果發生轉換錯誤, *_ok_設置為False ,否則*_ok_設置為True 。 **Note:**在默認的C語言環境下進行數字轉換,而不論用戶的語言環境。 **See also** [number](qbytearray.html#number)( ) 。 ``` (int, bool?ok) QByteArray.toUInt (self, int?base?=?10) ``` 返回字節數組轉換為`unsigned int`使用基_base_,它默認為10 ,并且必須是2和36 ,或0之間。 If _base_為0時,該基地是使用以下規則自動確定:如果字節數組開始以“0x” ,它被假定為十六進制的,如果它以“ 0 ”時,它被假定為八進制,否則它被假定為是小數。 返回0,如果轉換失敗。 If _ok_不為0 :如果發生轉換錯誤, *_ok_設置為False ,否則*_ok_設置為True 。 **Note:**在默認的C語言環境下進行數字轉換,而不論用戶的語言環境。 **See also** [number](qbytearray.html#number)( ) 。 ``` (int, bool?ok) QByteArray.toULong (self, int?base?=?10) ``` 返回字節數組轉換為`unsigned long int`使用基_base_,它默認為10 ,并且必須是2和36 ,或0之間。 If _base_為0時,該基地是使用以下規則自動確定:如果字節數組開始以“0x” ,它被假定為十六進制的,如果它以“ 0 ”時,它被假定為八進制,否則它被假定為是小數。 返回0,如果轉換失敗。 If _ok_不為0 :如果發生轉換錯誤, *_ok_設置為False ,否則*_ok_設置為True 。 **Note:**在默認的C語言環境下進行數字轉換,而不論用戶的語言環境。 這個函數是Qt 4.1中引入。 **See also** [number](qbytearray.html#number)( ) 。 ``` (int, bool?ok) QByteArray.toULongLong (self, int?base?=?10) ``` 返回字節數組轉換為`unsigned long long`使用基_base_,它默認為10 ,并且必須是2和36 ,或0之間。 If _base_為0時,該基地是使用以下規則自動確定:如果字節數組開始以“0x” ,它被假定為十六進制的,如果它以“ 0 ”時,它被假定為八進制,否則它被假定為是小數。 返回0,如果轉換失敗。 If _ok_不為0 :如果發生轉換錯誤, *_ok_設置為False ,否則*_ok_設置為True 。 **Note:**在默認的C語言環境下進行數字轉換,而不論用戶的語言環境。 **See also** [number](qbytearray.html#number)( ) 。 ``` QByteArray QByteArray.toUpper (self) ``` [ 返回字節數組的大寫副本。從ByteArray中被解釋為Latin-1的編碼字符串。 例如: ](qbytearray.html) ``` QByteArray x("Qt by NOKIA"); [QByteArray](qbytearray.html) y = x.toUpper(); // y == "QT BY NOKIA" ``` **See also** [toLower](qbytearray.html#toLower)()和[8-bit Character Comparisons](qbytearray.html#8-bit-character-comparisons)。 ``` (int, bool?ok) QByteArray.toUShort (self, int?base?=?10) ``` 返回字節數組轉換為`unsigned short`使用基_base_,它默認為10 ,并且必須是2和36 ,或0之間。 If _base_為0時,該基地是使用以下規則自動確定:如果字節數組開始以“0x” ,它被假定為十六進制的,如果它以“ 0 ”時,它被假定為八進制,否則它被假定為是小數。 返回0,如果轉換失敗。 If _ok_不為0 :如果發生轉換錯誤, *_ok_設置為False ,否則*_ok_設置為True 。 **Note:**在默認的C語言環境下進行數字轉換,而不論用戶的語言環境。 **See also** [number](qbytearray.html#number)( ) 。 ``` QByteArray QByteArray.trimmed (self) ``` [ 返回一個字節數組,它已經從空白開始和結束時刪除。 空白單元,對標準C + +的使用isspace ( )函數返回True的任何字符。這包括ASCII字符'\ T' ,為'\ n ',' \ V' , '\ F' , ' \ r '和' “ 。 例如: ](qbytearray.html) ``` QByteArray ba(" lots\t of\nwhitespace\r\n "); ba = ba.trimmed(); // ba == "lots\t of\nwhitespace"; ``` 不像[simplified](qbytearray.html#simplified)( ) ,修剪( )獨葉內部的空白。 **See also** [simplified](qbytearray.html#simplified)( ) 。 ``` QByteArray.truncate (self, int?pos) ``` 截斷該字節數組索引位置_pos_。 If _pos_超出了數組的結尾,沒有任何反應。 例如: ``` [QByteArray](qbytearray.html) ba("Stockholm"); ba.truncate(5); // ba == "Stock" ``` **See also** [chop](qbytearray.html#chop)( )[resize](qbytearray.html#resize)()和[left](qbytearray.html#left)( ) 。 ``` QByteArray QByteArray.__add__ (self, QByteArray?a2) ``` [ ``` QString QByteArray.__add__ (self, QString?s) ``` ``` int QByteArray.__contains__ (self, QByteArray?a) ``` ``` bool QByteArray.__eq__ (self, QString?s2) ``` ``` bool QByteArray.__eq__ (self, QByteArray?a2) ``` ``` bool QByteArray.__ge__ (self, QString?s2) ``` ``` bool QByteArray.__ge__ (self, QByteArray?a2) ``` ``` str QByteArray.__getitem__ (self, int?i) ``` ](qbytearray.html) ``` QByteArray QByteArray.__getitem__ (self, slice?slice) ``` [ ``` bool QByteArray.__gt__ (self, QString?s2) ``` ``` bool QByteArray.__gt__ (self, QByteArray?a2) ``` ``` int QByteArray.__hash__ (self) ``` ](qbytearray.html) ``` QByteArray QByteArray.__iadd__ (self, QByteArray?a) ``` [](qbytearray.html) ``` QByteArray QByteArray.__iadd__ (self, QString?s) ``` [](qbytearray.html) ``` QByteArray QByteArray.__imul__ (self, int?m) ``` [ ``` bool QByteArray.__le__ (self, QString?s2) ``` ``` bool QByteArray.__le__ (self, QByteArray?a2) ``` ``` QByteArray.__len__ (self) ``` ``` bool QByteArray.__lt__ (self, QString?s2) ``` ``` bool QByteArray.__lt__ (self, QByteArray?a2) ``` ](qbytearray.html) ``` QByteArray QByteArray.__mul__ (self, int?m) ``` [ ``` bool QByteArray.__ne__ (self, QString?s2) ``` ``` bool QByteArray.__ne__ (self, QByteArray?a2) ``` ``` str QByteArray.__repr__ (self) ``` ``` str QByteArray.__str__ (self) ``` ](qbytearray.html)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看