my ip address is declared as : const QString &ip
How can i increment/decrement the ip addresses stored in this string. (for ex: ip=192.168.1.1, then increment is 192.168.1.2)?
my ip address is declared as : const QString &ip
How can i increment/decrement the ip addresses stored in this string. (for ex: ip=192.168.1.1, then increment is 192.168.1.2)?
Split the string by '.'. Convert the last to integer (toInt()), increment, convert it to a string (QString::number()) and join the previous splited strings together.
Ignoring network masks and other potential errors:
Qt Code:
qDebug() << next.toString();To copy to clipboard, switch view to plain text mode
premroxx (23rd March 2012)
Am i doing something wrong here?
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QDebug"
#include "QString"
#include "QtNetwork/qhostaddress.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString ip("192.168.1.1");
QHostAddress next(QHostAddress(ip).toIPv4Address() + 1);
qDebug() << next.toString();
}
I am getting the following LINK errors
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QString __thiscall QHostAddress::toString(void)const " (__imp_?toString@QHostAddress@@QBE?AVQString@@XZ) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::~QHostAddress(void)" (__imp_??1QHostAddress@@QAE@XZ) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(unsigned int)" (__imp_??0QHostAddress@@QAE@I@Z) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall QHostAddress::toIPv4Address(void)const " (__imp_?toIPv4Address@QHostAddress@@QBEIXZ) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(class QString const &)" (__imp_??0QHostAddress@@QAE@ABVQString@@@Z) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)
debug\tag.exe : fatal error LNK1120: 5 unresolved externals
Yes
Try adding:
to your pro file.
premroxx (23rd March 2012)
Bookmarks