QUrl url("http://username:[email protected]/path/to/file"); QString userName = url.userName(); qDebug() << "User name: " << userName;
QUrl url("ftp://example.com/file.txt"); QString userName = url.userName(); if(userName.isEmpty()) { qDebug() << "No user name in URL"; } else { qDebug() << "User name: " << userName; }In this example, the URL does not contain a user name, so the isEmpty method is used to check and print a message indicating that there is no user name in the URL. The QUrl class is part of the Qt Core module.