因为您的方法被声明为static
,所以您不能直接访问非静态成员ui
。
改变
static void AutoFish::updatelabel(QString str);
到
void updatelabel(QString str);
在你的头文件中。
There is no need for static
keyword, because you want to set label for the specific instance of the window. Also, there is no need for AutoFish::
as you are declaring a method inside class declaration (however, you do need it in your cpp file).
As per the second error - inside your getWindow
function, you need to have a instance of the AutoFish
object in order to call updateLabel
. So, either change your getWindow
definition to:
HWND getWindow(AutoFish *af, LPCSTR processName)
{
HWND hwnd = FindWindowA(0, processName);
if(!hwnd) {
std::cout << "Error: Cannot find window!" << std::endl;
af->updatelabel("Error: Cannot find window.");
}
else {
std::cout << "Seccess! Window found!" << std::endl;
af->updatelabel("Seccess! Window Found!");
}
return hwnd;
}
and call it like this:
HWND window = getWindow(this, "FFXIVLauncher");
or make getWindow
member of AutoFish
class:
class AutoFish : public QMainWindow
{
// ...
HWND getWindow(LPCSTR processName);
// ...
};
HWND AutoFish::getWindow(LPCSTR processName) {
HWND hwnd = FindWindowA(0, processName);
if(!hwnd) {
std::cout << "Error: Cannot find window!" << std::endl;
updatelabel("Error: Cannot find window.");
}
else {
std::cout << "Seccess! Window found!" << std::endl;
updatelabel("Seccess! Window Found!");
}
return hwnd;
}
and this
pointer will be implicitely passed to the getWindow
.