|
Member 14968771 wrote: error: unknown type name 'num'
That's pretty clear, I think. But here's the scoop - when pulling arguments out of a va_list , the second argument to va_arg is a type , not a variable name. So in your case this should be
QString s;
for(int i = 0; i < num; ++i)
s = va_arg(args, QString)
Keep Calm and Carry On
|
|
|
|
|
Message Closed
modified 15-May-23 19:07pm.
|
|
|
|
|
This is the mechanism that printf() uses to pass mixed arguments in, so its definitely doable. printf uses its format string to help unpack the argument list, but there are other ways. You could use a simplified format string like "sddi" , showing that the unspecified arguments are a string , two double s and an int . Another option might be to use an indicator e.g
#define ARG_INT 1
#define ARG_LONG 2
#define ARG_DOUBLE 3
#define ARG_CHAR 4
#define ARG_STRING 5
#define ARG_END -1
int var_arg_fn(int arg, ...)
{
va_ist args;
va_start(args, arg);
while(arg != ARG_END) {
switch(arg) {
case ARG_INT :
{
int i = va_arg(args, int);
break;
}
case ARG_DOUBLE :
{
double d = va_arg(args, double);
break;
}
default:
}
arg = va_arg(args, int);
}
}
var_arg_fn(ARG_INT, 1, ARG_DOUBLE, 3.2, ARG_STRING, strvar, ARG_END); I'm sure if you think about it, you can come up with something that suits your needs.
But since you're using C++ now might be the time to venture into the world of variadic fuction templates . Google for that and check out one or more of the tutorials and/or examples. It might be a better fit than trying to wrap things back down to C stdargs .
Update: Here's a video on variadic templates that may help
C++ Weekly - Ep 6 Intro To Variadic Templates - YouTube
Keep Calm and Carry On
modified 9-Jan-22 18:37pm.
|
|
|
|
|
Where is i used in the call to va_arg ?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Its only used as a loop counter. If you prefer we could do
while(num--)
{
s = val_arg(args, QString);
} That, of course alters the value of num, so if you need to know how many args were passed in, or need to traverse the argument list again, you don't want to do that.
Keep Calm and Carry On
|
|
|
|
|
Message Closed
modified 15-May-23 19:07pm.
|
|
|
|
|
Member 14968771 wrote: PS I did post same request on QT forum
Given the complete lack of detail in your "question", you'd have better luck posting it on a "psychic hotline" forum instead.
Even people who are "familiar with QT Bluetooth CODING" can't guess what your secret code is doing, nor what the secret problem is.
If you want someone to help you, you need to start by asking a proper question, with enough details to explain the problem and to show the relevant parts of your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
is there how to work on google even knowing any programming language variation? 
|
|
|
|
|
Uhh... what?
And what does this have to do with C/C++?
|
|
|
|
|
Not with those types of questions.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
If you're looking for work at Google or another international (and especially US-based) company, you should work on your grasp of the english language first.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Hi
I have a question regarding the pie method in CDC there are eight parms the first 4 represent the bounding rectangle in which the ellipse or the circle is enclosed the last 4 represent the starting and ending points and of the arc
my question is for the last 4 why is the "Y' vertical parm necessary it would always seem to be from the center of the arc to its edge
I hope my question makes sense
thanks
|
|
|
|
|
"Y", the radius at x = 0, varies with the angle of the arc (as a point on the circumference).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Tell me if I am right I think I first need to determine the angle so if is 25 % then the angle is 90 4 / 360 then to get the y it’s y = consin(angle) x = sin(angle)
Right ?
|
|
|
|
|
|
Thanks for help one more follow up question
Would this equation not have to be multiplied by the number of pixels per circle degree I mean the formula is the same for big and small circles so you have to taken into account the size of the circle I’m sure I can do it with GetCientrect
Thanks
|
|
|
|
|
The radius determines the size of a circle. If you want to scale, you vary the radius.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
My client etc is a square so either the width or height divided by 2
Ok thanks
|
|
|
|
|
When doing drawing first you do it to memory than BitBlt to the device -> device context can to you save the memory dc to a file ?
thanks
|
|
|
|
|
|
I am writing a pie chart using pie and ellipse first doing CreateCompatableBitmap Selecting to mem dc but the example will work
thanks
|
|
|
|
|
No, as shown in the documentation at GetDC function (winuser.h) - Win32 apps | Microsoft Docs[^]:
Quote: The GetDC function retrieves a handle to a device context (DC) for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. The device context is an opaque data structure, whose values are used internally by GDI.
You need to save other information that you use to create the drawing.
|
|
|
|
|
I am writing a pie chart using pie and ellipse first doing CreateCompatableBitmap Selecting to mem dc but the example will work
Mircea provided an example that will work for me
thanks
|
|
|
|
|
ForNow wrote: Mircea provided an example that will work for me
Yes. However in this example the bitmap is saved into the file, and not the memory or some other DC (device context)!
|
|
|
|
|
The incomplete code bellow doesnt seem to be working as intended. I would be really gratefull to any help.
#include<iostream>
#include <fstream>
#include<cstring>
using namespace std;
const int N=20; <pre lang="C++"><pre lang="text"><pre lang="C++"></pre></pre></pre>
const char Filename[]= "Shiplist.dat";
struct Ship {
unsigned int number;
float capacity;
char name[50];
};
fstream sp;
int menu() {
int choice;
cout << "\n \t MENU";
cout << "\n 1. Add individual ships";
cout << "\n 2. Add a list of ships";
cout << "\n 3. Print the list of all ships on screen";
cout << "\n 4. Show the ships with the biggest load capacity ";
cout << "\n 5. Search ship by name";
cout << "\n 6. Add shipments";
cout << "\n 7. Cancel shipments";
cout << "\n 8. Save ship information";
cout << "\n 9. Add new ship to the list";
cout << "\n 10. Exit";
do {
cout << "\n Your choice:"; cin >> choice;
} while (choice<1 || choice>10);
return choice;
}
Ship input () {
Ship S= { 0 };
cin.ignore();
cout << "\n Enter ship number:"; cin >> S.number;
cin.ignore();
cout << "\n Enter the name of the ship:"; cin.getline(S.name,50);
cout << "\n Enter the load capacity of the ship:"; cin >> S.capacity;
return (S);
}
int enter (Ship Lib[], int n) {
int i, m;
do {
cout << "\n Enter information for how many ships(max 5 in one go):";
cin >> m;
} while(m<0 || m>5);
if (n+m < 20) {
for (i= n; i<n+m; i++) {
cout << "\n Ship " << i+1;
Lib[i]= input();
}
return (n+m);
} else cout << "\n You can't add any more ships!";
}
void Save_File (Ship Lib[], int n) {
sp.open(Filename, ios::binary | ios::out);
if (!sp) { cout << "\n Error in file! \n"; exit(1); }
sp.write((char*)Lib, sizeof(Ship) * n);
sp.close();
}
void append () {
Ship b= { 0 };
sp.open(Filename, ios::binary | ios::app);
if (!sp) { cout << "\n Error in file! \n"; exit(1); }
cout << "\n Add a new ship to the list \n";
b= input();
sp.write((char*)&b, sizeof(Ship));
sp.close();
}
void output (Ship Lib[], int n) {
int i, k=0;
cout << "\n \t List of all ships \n";
for (i=0; i<n; i++) {
cout << "\n" << i+1 << "\t" << Lib[i].number << " " << Lib[i].name << " " << Lib[i].capacity ;
k++; if(k % 5 == 0) cout << "\n\n\n\n\n\n";
}
}
int Load_File (Ship Lib[]) {
long pos; int n=0, i; Ship b;
sp.open(Filename, ios::binary | ios::in);
if (!sp) { cout << "\n File doesn't exist!! \n"; return n; }
sp.seekg(0L, ios::end);
pos= sp.tellg();
sp.close();
n= pos/ (sizeof(Ship));
sp.open(Filename, ios::binary | ios::in);
if (!sp) { cout << "\n Error in file! \n"; exit(1); }
for (i=0; i<n; i++) {
sp.read((char*)&b, sizeof(Ship));
Lib[i]=b;
}
sp.close();
return n;
}
void Ship_by_Name (Ship Lib[], int n) {
char Sname[50];
cin.ignore();
cout << "\n Ship name: ";
cin.getline(Sname, 50);
for (int i = 0; i < n; i++)
if (!strcmp(Sname, Lib[i].name)) {
cout << "\n Ship found!";
cout << "\n Number: " << Lib[i].number << "\t Name: " << Lib[i].name << "\t Load capacity: "
<< Lib[i].capacity;
break;
} else cout << "\n This ship isn't recorded!";
}
int main () {
int choice, n=0;
Ship Lib[N];
char answ= 'y';
n= Load_File(Lib);
do {
choice= menu();
switch (choice) {
case 1: input(); break;
case 2: n= enter(Lib, n); Save_File(Lib, n); break;
case 3: n= Load_File(Lib); output(Lib, n); break;
case 5: n= Load_File(Lib); Ship_by_Name(Lib, n); break;
case 8: Save_File(Lib, n); break;
case 9: do {
append(); n++;
cout << "\n One more[y/n]? " << "\n Answer: "; cin >> answ;
Save_File(Lib, n);
} while (!(answ == 'N' || answ == 'n')); break;
}
} while (choice != 10);
}
|
|
|
|