Created
February 3, 2020 06:18
-
-
Save iamazeem/038f96840dbe816862f73a1c68e63ac9 to your computer and use it in GitHub Desktop.
Qt URL Organization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ref: https://stackoverflow.com/questions/60023890/organize-all-urls-in-one-place-inside-a-class | |
#include <QDebug> | |
#include <QString> | |
#include <QUrl> | |
namespace url { | |
static constexpr auto default_ip = "localhost"; | |
static constexpr auto default_port = "8080"; | |
static constexpr auto about = "about"; | |
static constexpr auto services = "services"; | |
static constexpr auto products = "products"; | |
QUrl fmt( const QString& route, const QString& ip = default_ip, const QString& port = default_port ) noexcept | |
{ | |
static const auto fmt = QString{ "http://%1:%2/%3" }; | |
return fmt.arg(ip).arg(port).arg(route); | |
} | |
} // url | |
int main() | |
{ | |
constexpr auto ip = "192.168.123.123"; | |
constexpr auto port = "9090"; | |
const auto about = url::fmt( url::about ); | |
const auto services = url::fmt( url::services ); | |
const auto products = url::fmt( url::products, ip, port ); | |
qDebug() << about; | |
qDebug() << services; | |
qDebug() << products; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment