QByteArray byteArray("Hello World"); QByteArray searchArray("World"); int index = byteArray.indexOf(searchArray); // index will have value 6
QByteArray byteArray("This is an example"); QByteArray searchArray("test"); int index = byteArray.indexOf(searchArray); // index will have value -1In the above example, we have initialized another QByteArray object with the string "This is an example". We then create a search array with the string "test". We apply the indexOf function to the first string to search for the occurrence of the second string. Since the string "test" is not found in the first string, it returns -1. Package Library: Qt C++ Library.