Hi, maybe you guys can help me out.
I'm new to QT (and C++) and am trying to create a SIGNAL/SLOT event which closes the current QApp and starts another .exe based on a QPushButton click() signal. But its not working correctly. I believe I have more than one error.
With the code I put below, I get an "Access violation reading location 0x00000000 error" when compiling, and the debug output reads "Object::connect: No such slot Lobby::StartGame(menuMap[buttonItor->second->GetTarget()])"
I've put what I think is the most relevant code below. Let me know if you need more info.
//Lobby.h
{
Q_OBJECT
public:
Lobby
::Lobby(int argc,
char *argv
[]) : QApplication(argc, argv
){} ~Lobby(){}
void LoadMenus();
public slots:
};
//Lobby.h
class Lobby : public QApplication
{
Q_OBJECT
public:
Lobby::Lobby(int argc, char *argv[]) : QApplication(argc, argv){}
~Lobby(){}
void LoadMenus();
public slots:
void StartGame(QString target);
};
To copy to clipboard, switch view to plain text mode
//Lobby.cpp
void Lobby
::StartGame(QString target
) {
startGame.execute(target);
}
void Lobby::LoadMenus()
{
//iterate through button map, making the proper connections
for(std::map<QString, LobbyButton *>::iterator buttonItor = buttonMap.begin(); buttonItor != buttonMap.end(); ++buttonItor)
{
if(buttonItor->second->GetType() == "screen")
{
QObject::connect(buttonItor
->second,
SIGNAL(clicked
()), menuMap
[buttonItor
->second
->GetTarget
()],
SLOT(show
()));
QObject::connect(buttonItor
->second,
SIGNAL(clicked
()), menuMap
[buttonItor
->second
->GetBoundMenu
()],
SLOT(hide
()));
}
if(buttonItor->second->GetType() == "game")
{
QObject::connect(buttonItor
->second,
SIGNAL(clicked
()),
this,
SLOT(StartGame
(menuMap
[buttonItor
->second
->GetTarget
()])));
QObject::connect(buttonItor
->second,
SIGNAL(clicked
()),
this,
SLOT(quit
()));
}
}
//Lobby.cpp
void Lobby::StartGame(QString target)
{
QProcess startGame;
startGame.execute(target);
}
void Lobby::LoadMenus()
{
//iterate through button map, making the proper connections
for(std::map<QString, LobbyButton *>::iterator buttonItor = buttonMap.begin(); buttonItor != buttonMap.end(); ++buttonItor)
{
if(buttonItor->second->GetType() == "screen")
{
QObject::connect(buttonItor->second, SIGNAL(clicked()), menuMap[buttonItor->second->GetTarget()], SLOT(show()));
QObject::connect(buttonItor->second, SIGNAL(clicked()), menuMap[buttonItor->second->GetBoundMenu()], SLOT(hide()));
}
if(buttonItor->second->GetType() == "game")
{
QObject::connect(buttonItor->second, SIGNAL(clicked()), this, SLOT(StartGame(menuMap[buttonItor->second->GetTarget()])));
QObject::connect(buttonItor->second, SIGNAL(clicked()), this, SLOT(quit()));
}
}
To copy to clipboard, switch view to plain text mode
I'd appreciate any help you can give me.
EDIT: I posted this in another forum and someone mentioned that if my SLOT method takes a parameter then my SIGNAL must emit that parameter. Do you think that has anything to do with my current problem?
Bookmarks