|
|
But true.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Sorry, I posted this is wrong forum.
But to the comedians - do not quit you day job.
In the mean time I'll looking at usage of "friend".
|
|
|
|
|
Member 14968771 wrote: In the mean time I'll looking at usage of "friend".
Don't waste your time, since it will not make any difference. You cannot declare your class to be a friend of some other class in the hope of accessing its private variables. If that was possible then the millions of applications would be open to hacking. Do what I suggested above and make use of the information provided in the documentation: that is what it is there for..
|
|
|
|
|
It was serious, actually. If you the designer of the class made a member private then you have two ways to access it: the publicly exposed interface (for instance the get/set methods) or a dirty hack on its bare representation in memory. Typically you cannot use friend because you are not the designer of the class.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Private members are only accessible via public functions.
Try int start_X = QPoint.SetX(dimentions.x2);
|
|
|
|
|
Reason for this post is
I am trying to learn not just "cut and paste".
In the following code I am trying to put a function with parameter into "addAction " function It fails with two errors I am trying to decipher and learn what I am doing wrong.
I tested
Run_DDD_OPTION(testWidget); and it runs fine
<pre> QWidget *testWidget = new QWidget();
testWidget->setWindowTitle("test widget window ");
Run_DDD_OPTION(testWidget); runs fine
QAction *CAT_DDD_OPTION = CATMenu->
addAction(tr("&Device Discovery Dialog (modified Bluetooth scanner ) "),
this,
&MainWindow::Run_DDD_OPTION(testWidget)
);
this runs as expected when no parameters are passed
QAction *CAT_DDD_OPTION_TAB = CATMenu->
addAction(tr("&Device Discovery Dialog (modified Bluetooth scanner ) "),
this,
&MainWindow::Run_TAB
);
There are too many "addAction" functions , different objects, so all I have to go by are these errors. (It woudl probably help if I knew what "addAction" expects as parameters.
<pre>/media/qe/TSET_QT_LABEL/QT_PROGRAMS/JUNE 15 WORKCOPY 2/CAT/mdi/mainwindow.cpp:1157: error: lvalue required as unary ‘&’ operand
../../../JUNE 15 WORKCOPY 2/CAT/mdi/mainwindow.cpp: In member function ‘void MainWindow::createActions()’:
../../../JUNE 15 WORKCOPY 2/CAT/mdi/mainwindow.cpp:1157:32: error: lvalue required as unary ‘&’ operand
1157 | &MainWindow::Run_DDD_OPTION(testWidget)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
/media/qe/TSET_QT_LABEL/QT_PROGRAMS/JUNE 15 WORKCOPY 2/CAT/mdi/mainwindow.cpp:1155: error: cannot take the address of an rvalue of type 'void'
|
|
|
|
|
This looks suspicious to me:
&MainWindow::Run_DDD_OPTION(testWidget)
It looks like you're trying to create a pointer to whatever Run_DDD_OPTION returns. However, you also say
Run_DDD_OPTION(testWidget); which either means that it returns void or you didn't care what it returned. My guess is the former, which would explain all the error messages. If it returns void , you can't take its address, and there is no lvalue (=a memory address).
EDIT: If you want to pass the function Run_DDD_OPTION as an argument to addAction, just write
addAction(tr("&Device Discovery Dialog(modified Bluetooth scanner)"),
this,
MainWindow::Run_DDD_OPTION
); You may need the & in front of the function name--I haven't done this in a long time, so I have to look it up. --It looks like it's optional. If it doesn't work without it, try it with it.
modified 15-Jun-21 17:48pm.
|
|
|
|
|
Thanks
I think you may have answered my question.
The line is just to test validity of the function.
Run_DDD_OPTION(testWidget);
addAction(tr("&Device Discovery Dialog(modified Bluetooth scanner)"),
this,
MainWindow::Run_DDD_OPTION
);
The above code works IF "&" is prefixed ,
HOWEVER I like to make that parameter of "addAction" variable, more versatile.
And that is why I am having issues, hence my post.
&MainWindow::Run_DDD_OPTION
So my question would be
if this works without parameter
why do I need to return a pointer ?
I presume it would be same as the passed parmeter type.
Run_DDD_OPTION
Now again , I just do not want to "cut and paste" without knowing why.
Thanks for your contribution.
|
|
|
|
|
I don't understand how you want to make addAction's last parameter "more versatile". You'll have to explain that.
|
|
|
|
|
Simple, the app will use several GUI interfaces - in Qt terminology "widgets".
There is lots of commonality and I like to reuse my code.
So passing "widget" as a parameter to addAction would be nice.
Besides - I need to get over this "passing function as a parameter with parameters ".
I have a feeling QT makes its own syntax...
Should that be
function ( passFunction, passFunctionparamater ); // pointer , pointer
|
|
|
|
|
I haven't used Qt, so I don't know if I can help. It sounds like a widget is an object, but you're only passing functions and parameters. Would passing an object help?
It's even possible to pass a class's member function[^] as a parameter. I've not used this capability, so you'd have to read up on it if that's what you want.
The problem with passing a function and its parameters is that different functions take different parameters. To deal with that, I think you'd need std::function[^]. Again, that's not something I've used, but now you can look for more details.
My go-to site for C++ is here[^]. It's a bit formal, so sometimes you need to look elsewhere for explanations and examples that are easier to understand. But it will provide you with the right terminology to use when investigating something.
|
|
|
|
|
class A
{
public:
int a;
};
class B:public class A
{
public:
int b;
}
class C: public class B
{
public:
B obj;
}
void main()
{
C obj1(10,20);
}
How do you write constructor for all three class so that the main will get called/?
|
|
|
|
|
Member 15229174 wrote: ...so that the main will get called/?
main() is called by the OS/framework, not you.
If, instead, you wanted to know how to call the base class constructor, how about something like:
class C : public B
{
public:
C(int x, int y) : B(x, y)
{
}
};
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Actually an interviewer asked me this question and told that class C contains the object of B class and through main C obj1(10,20) should be passed. Now you have to write constructor in all three class so that in main() function, it will not give an error.
|
|
|
|
|
Since all the member variables are public you only need a constructor in C. And it would still work without that.
|
|
|
|
|
you C class does not have a constructor with 2 parameters.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
Actually class C constructor should have had four (Yes, 4 , since it contains four variables) parameters. Anyway...
Try
#include <iostream>
using namespace std;
class A
{
public:
int a;
A(int a):a(a){}
};
class B: public A
{
public:
int b;
B(int a, int b): A(a), b(b){}
};
class C: public B
{
public:
B obj;
C(int a, int b): B(a, b), obj(b, a){} friend ostream & operator << (ostream & os, const C & c); };
ostream & operator << (ostream & os, const C & c)
{
os << "a = " << c.a << ", b = " << c.b << ", obj.a = " << c.obj.a << ", obj.b = " << c.obj.b;
return os;
}
int main()
{
C obj1(10,20);
cout << obj1 << endl;
}
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Some of my employer's customers have old Windows-computers (some are from the 90's) and they are not allowed to connect to the Internet and they have no Service Packs or Frameworks installed. I need to write a simple GUI application that does some UART-communication that can run on these old computers and I would greatly appreciate some advice.
1. What API would you recommend I use? I've heard of an API called "Win32", is that the one I should use?
2. What GUI library would you recommend I choose?
3. Can I program in C++ or am I restricted to C?
4. Is Visual Studio 2005 a good choice for an IDE or would you recommend something else?
5. Anything else I need to be aware of?
|
|
|
|
|
- Win32 API
- VC++ MFC application
- C++
- VC++6.0
|
|
|
|
|
1. What API would you recommend I use? I've heard of an API called "Win32", is that the one I should use? Most probably. At that time there weren't many other choices.
2. What GUI library would you recommend I choose? You don't necessarily need a GUI library. Win32 was quite capable of making a simple GUI app.
3. Can I program in C++ or am I restricted to C? You can use C++.
4. Is Visual Studio 2005 a good choice for an IDE or would you recommend something else? VS 2019 is WAY better and you can target 32-bit Win32 applications.
5. Anything else I need to be aware of? Link everything statically. You don't want to depend on runtime DLLs. Keep it simple, keep it small.
Mircea
|
|
|
|
|
|
arnold_w wrote: (some are from the 90's) What is exactly the lowest specification without being that vague?
arnold_w wrote: 1. What API would you recommend I use? I've heard of an API called "Win32", is that the one I should use? There's no other real option.
arnold_w wrote: 2. What GUI library would you recommend I choose? Win32, native. It is recogniazable and works well with accessability features.
arnold_w wrote: 3. Can I program in C++ or am I restricted to C? I restrict you to Delphi. Lots simpeler than C++, makes you more productive.
arnold_w wrote: 4. Is Visual Studio 2005 a good choice for an IDE or would you recommend something else? It is, for non-Delphi apps.
arnold_w wrote: 5. Anything else I need to be aware of? If you need to ask what language, you're not up to the task. Run.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
arnold_w wrote: 5. Anything else I need to be aware of? |
poor you.
your only choice is win32.
I suggest setting up a virtual machine with the target OS (if it's possible) on which you can do your work (install VS2005... )
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
I'm trying to determine this value for a system-status program that I maintain.
In the past, I've just shown Uptime, but now that I'm forced to Windows 10, that isn't entirely informative!! If I log out of my machine (shutdown -l) and then log back in, Uptime doesn't get reset. So I want to add an option to show logon time vs reboot time (Uptime)... but I'm not having much success with this...
I have found several articles which recommend NetUserGetInfo(), but this is returning invalid data for me... for example, I just logged out, and back in, to my machine... here is the code, followed by the results that I get:
dwLevel = 2;
wchar_t username[UNLEN+1];
DWORD username_len = UNLEN+1;
GetUserNameW(username, &username_len);
nStatus = NetUserGetInfo(NULL, username, dwLevel, (LPBYTE *) & pBuf);
pBuf2 = (LPUSER_INFO_2) pBuf;
wprintf(L"User account name: %s\n", pBuf2->usri2_name);
wprintf(L"Password age (seconds): %d\n", pBuf2->usri2_password_age);
wprintf(L"Last logon (seconds since January 1, 1970 GMT): %d\n", pBuf2->usri2_last_logon);
time_t logon_time = pBuf2->usri2_last_logon ;
char buff[20];
strftime(buff, 20, "%Y-%m-%d %H:%M:%S", localtime(&logon_time));
printf("logon time: %s\n", buff);
The results that I get are:
User account name: dan7m
Password age (seconds): 10221317
Last logon (seconds since January 1, 1970 GMT): 1616249786
logon time: 2021-03-20 07:16:26
Note that the logon time *actually* around 1920 on 06/05/21...
So I have two questions, I guess...
1. is there some way to make this function actually work??
2. if not, how else can I programmatically access the login time on Windows 10 64bit??
|
|
|
|
|