#include#include #include using namespace std; int main() { ifstream inputFile("example.txt"); if (!inputFile) { ResourceError error(QResourceError::FileError, "example.txt", "Cannot open file"); cerr << "Error: " << error.errorCode() << endl; cerr << "Description: " << error.description().toStdString() << endl; return -1; } // file is open and ready to read // ... inputFile.close(); return 0; }
#includeThis code tries to connect to the website www.google.com on port 80 using a network socket. If it fails, it creates a ResourceError object with a description of the error and prints the error code and description to the console. The ResourceError class is part of the Qt framework.#include #include using namespace std; int main() { QTcpSocket socket; socket.connectToHost("www.google.com", 80); if (!socket.waitForConnected()) { ResourceError error(QResourceError::ConnectionError, "www.google.com:80", "Cannot establish connection"); cerr << "Error: " << error.errorCode() << endl; cerr << "Description: " << error.description().toStdString() << endl; return -1; } // socket is connected and ready to use // ... socket.disconnectFromHost(); return 0; }