The problem is that my instruction in QT 4 was limited mainly to the GUI, which I understand great. But it lacks in practical application. In other words, I'm having trouble getting my GUI code to blend with the libyahoo2 functions. The specific problem I'm getting is during the compile stage and appears to be dealing with scope.
See, I have a struct that should be global;
struct yahoo_local_account {
char yahoo_id[255];
char password[255];
int id;
int fd;
int status;
char *msg;
};
static yahoo_local_account * ylad = NULL;
struct yahoo_local_account {
char yahoo_id[255];
char password[255];
int id;
int fd;
int status;
char *msg;
};
static yahoo_local_account * ylad = NULL;
To copy to clipboard, switch view to plain text mode
And then I have a member function, which should have access to the global struct, right?;
void YahooLogin::okClicked()
{
// accept QString input
QString username
= lineEditUsername
->text
();
QString password
= lineEditPassword
->text
();
// convert QString to string
std::string usrnm = username.toStdString();
std::string psswrd = password.toStdString();
// convert string to const char and assign struct values
std::strcpy(ylad->yahoo_id, usrnm.c_str());
std::strcpy(ylad->password, usrnm.c_str());
//get the session id from yahoo_init, which is a libyahoo2 function from <libyahoo2/yahoo2.h>
ylad->id = yahoo_init(ylad->yahoo_id, ylad->password);
}
void YahooLogin::okClicked()
{
// accept QString input
QString username = lineEditUsername->text();
QString password = lineEditPassword->text();
// convert QString to string
std::string usrnm = username.toStdString();
std::string psswrd = password.toStdString();
// convert string to const char and assign struct values
std::strcpy(ylad->yahoo_id, usrnm.c_str());
std::strcpy(ylad->password, usrnm.c_str());
//get the session id from yahoo_init, which is a libyahoo2 function from <libyahoo2/yahoo2.h>
ylad->id = yahoo_init(ylad->yahoo_id, ylad->password);
}
To copy to clipboard, switch view to plain text mode
This provides me with 2 separate compiler problems, 1st is that ylad is not declared in this scope, and 2nd is the reference to yahoo_init is undefined.
Now, obviously I am missing something. It was my understanding that if the struct is placed before the main() that it would be global, meaning that it would be accessible from every piece of code after it. But in order to remedy the 1st compile error, I have to move the struct (which I had located in its own file yahoo2.cpp, which was in-turn #included in my main.cpp) directly into the yahooLogin.cpp file above the member function, and ylad's declaration actually in the okClicked() member function.
That still leaves 2 problems, 1. is that now the struct is definitely not global and therefore useless beyond the okClicked member function, and 2. is that I still get the compile error with the call to yahoo_init().
Errors:
1st:
yahoologin.cpp: In member function ‘void YahooLogin::okClicked()’:
yahoologin.cpp:27: error: ‘ylad’ was not declared in this scope
yahoologin.cpp:30: error: ‘yahoo_init’ was not declared in this scope
2nd:
yahoologin.o: In function `YahooLogin::okClicked()':
yahoologin.cpp:(.text+0x12b): undefined reference to `yahoo_init'
collect2: ld returned 1 exit status
Qt:
$ qmake --version
QMake version 2.01a
Using Qt version 4.2.1 in /usr/lib
Make:
$ make --version
GNU Make 3.81
Compiler:
$ g++ --version
g++ (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Bookmarks