Skip to content

Instantly share code, notes, and snippets.

@ScatteredRay
Created October 27, 2009 05:41
Show Gist options
  • Save ScatteredRay/219344 to your computer and use it in GitHub Desktop.
Save ScatteredRay/219344 to your computer and use it in GitHub Desktop.
class BrowserWindow : public QMainWindow {
Q_OBJECT
private:
class AsyncServerQuery* Query;
...
public slots:
void ServerInfoReceived(struct SteamServerInfo Info);
};
BrowserWindow::BrowserWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::BrowserWindow)
{
...
Query = new AsyncServerQuery();
connect(Query, SIGNAL(ServerInfoReceived(SteamServerInfo)),
this, SLOT(ServerInfoReceived(SteamServerInfo)));
}
void BrowserWindow::ServerInfoReceived(SteamServerInfo Info)
{
// ERROR HERE!
QMessageBox::information(this, "Received Server Info", Info.ConnectAddress);
}
struct SteamServerInfo
{
...
QString ConnectAddress;
SteamServerInfo(const SteamServer& Address);
SteamServerInfo(const SteamServerInfo&);
};
class AsyncServerQuery : public QObject
{
Q_OBJECT
QThread* SQThread;
public:
AsyncServerQuery();
~AsyncServerQuery();
void QueryServerList();
signals:
void ServerInfoReceived(SteamServerInfo Info);
};
class ServerQuery : public QObject
{
Q_OBJECT
public:
...
ServerQuery();
~ServerQuery();
void GetServerList();
signals:
void ServerInfoReceived(SteamServerInfo Info);
};
Q_DECLARE_METATYPE(SteamServerInfo)
SteamServerInfo::SteamServerInfo(const SteamServer& Address)
{
...
ConnectAddress = Address.first.toString() + ":" + QString::number(Address.second);
}
SteamServerInfo::SteamServerInfo(const SteamServerInfo& O)
{
...
ConnectAddress = O.ConnectAddress;
}
void ServerQuery::GetServerList()
{
...
{
// Send query to the server.
printf("Server:%s\n", PendingQueries.front().first.toString().toAscii().data());
SteamServerInfo Info = SteamServerInfo(PendingQueries.front());
printf("Server Info:%s\n", Info.ConnectAddress.toAscii().data());
SteamServerInfo Info2(Info);
printf("Server Info2:%s\n", Info2.ConnectAddress.toAscii().data());
ServerInfoReceived(Info);
PendingQueries.pop_front();
}
}
class QueryThread : public QThread
{
AsyncServerQuery* QueryProxy;
public:
QueryThread(AsyncServerQuery* Receiving) : QueryProxy(Receiving)
{}
void run()
{
ServerQuery Query;
...
Query.connect(&Query, SIGNAL(ServerInfoReceived(SteamServerInfo)),
QueryProxy, SIGNAL(ServerInfoReceived(SteamServerInfo)),
Qt::QueuedConnection);
Query.GetServerList();
}
};
AsyncServerQuery::AsyncServerQuery()
{
SQThread = new QueryThread(this);
}
void AsyncServerQuery::QueryServerList()
{
SQThread->start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment