|
If I find I need to do something like this I do something like
#ifdef DEBUG
void foo( ... )
{
}
#endif
In debug mode, then I can call foo(arg, arg, arg, ... ) when I need to. Usually this would do something like print all the elements of a collection, for example.
As far as I know, you can't skip over code. You can set a break point at the top of the loop, and continue to that point. If you really want to omit portions of the loop in your debug testing the best I could suggest would be to wrap that in an #ifdef DEBUG/#endif. Alternatively, you might
#if DEBUG == 2
...
#endif Of course, you could use #if DEBUG <= 2 , etc to get different debug levels of code when you compile.
If you go that route, check with your IDE. It probably does not add a -DDEBUG to the compile command line in debug mode, so you'd have to do that yourself. If you want to have different debug levels you would pass -DDEBUG=2 (e.g.) (Linux - its probably different, but similar for windows)
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
modified 28-Jan-24 15:44pm.
|
|
|
|
|
Do you mean this (skip to next iteration)
for (int n=0; n<10; ++n)
{
cout << "working code A\n";
{
cout << "debug code, iteration = " << n << "\n";
continue;
}
cout << "working code B\n";
}
Or, possibly, this (skip the loop)
for (int n=0; n<10; ++n)
{
cout << "working code A\n";
{
cout << "debug code, iteration = " << n << "\n";
n=10; continue;
}
cout << "working code B\n";
}
?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
In C++
Macros
- As noted you can remove the code entirely
- You can also use a macro that resolves to a different value
For code
- Add a flag.
- Add a class that manages flags
Larger apps would use the second.
Your code then tests the flag. There are various ways the flags can be set: command line, config file, database. There are various ways to manage the class itself. Could be static or use a builder pattern.
Example of flag usage
if (myFlagClass.IsSet("TestFlag131")) ....
For systems (not just an app) can use special values in an API. The code of the target service looks for those special values and returns a fixed, or even variable, result. This is somewhat useful in verifying end to end enterprise functionality.
|
|
|
|
|
Voluntarily removed - wrong forum.
modified 27-Jan-24 16:00pm.
|
|
|
|
|
Salvatore Terress wrote: To make sure for people who "do not get it" - if you are not wiling to help,
please do not respond..
Kindly stop giving orders. As you have been repeatedly told, just post the question. If the answer is not to your exacting requirements, then you have two choices:
1. Politely ask for clarification.
2. Ignore it.
|
|
|
|
|
I tried placing the UpdateGame() function inside the window message processing loop but the execution never reaches that spot
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
UpdateGame();
}
}
I`m trying to mix code from two different tutorials which might be the cause of the problem. Bellow is what the initial message processing loop looked like.
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
|
|
|
|
|
At a guess PeekMessage() is always returning true. If you want UpdateGame() to always be called then remove it from the else block:
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UpdateGame();
}
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
Thanks for advice, I’ll give it a try
modified 27-Jan-24 11:28am.
|
|
|
|
|
I was told that if I want to call invalidate rectangle the space between begin paint and end paint is not a good place to set the dimensions of rectangles, hence I`m trying to create an update function for my game, a place where I can set the position and dimension of rectangles and also compute all sorts of other things required in the game. I borrowed this code from a DirectX tutorial
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
UpdateGame();
}
}
but the execution never reaches UpdateGame(). Could you please help me out find a place for UpdateGame()?
modified 26-Jan-24 6:35am.
|
|
|
|
|
You need to provide more details about what you are trying to do here. Calling UpdateGame in the message loop as you show, will only work if there are no messages in the queue. And given the way Windows operates, this is not very likely. The only thing you should do in your WM_PAINT handler, is to update the screen. All calculations and measurements should be performed elsewhere.
|
|
|
|
|
Original post edited, I hope it makes sense now
|
|
|
|
|
I just ran a quick test and the call to UpdateGame does indeed get called many times in a simple Window. You need to do some more debugging to find out why that does not happen in your code.
|
|
|
|
|
Wow, you're a game developer, now!
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
void UpdateGame()
{
MessageBox(hWnd, "Doing the update", "Game", MB_OK);
}
|
|
|
|
|
|
The second line of code does not compile and I get a ton of "helpful" messages.
I am asking the forum to help me to understand the messages.
I am not asking for RTFM...
If somebody is willing to help I will post the errors.
QAction tempAction;
subMenu[index]->addAction(" test ");
subMenu[index]->addAction(tempAction.setCheckable(true));
|
|
|
|
|
Posting such a question without the error message is not very helpful. Please make sure you post all the relevant information.
|
|
|
|
|
Don't make a post with a teensy bit of code and no errors, then ask "is someone willing to help?" Because if you don't supply ALL of the information on the problem, the answer is going to be NO. All you're doing is wasting time because now you have to wait for an answer of "Sure!" before you post the rest of the information required to solve the problem, then wait some more for an actual answer.
|
|
|
|
|
Best guess: you're mixing types; which only works for things "typed as object".
"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
|
|
|
|
|
Oh, so we need to pass a little test before we're allowed to respond to your post? How childish.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Please help us to answer your post.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
As noted not enough information.
And the cause is based on what the exact type (resolved by the compiler) for 'subMenu[index]'
So for example from Qt docs a QWidget addAction() method takes a pointer to a QAction. And in that case a char pointer would not work. (I got that by RTFM by the way.)
|
|
|
|
|
jschell wrote: I got that by RTFM by the way Me too, but I couldn't be bothered to edit my original reply. This guy really takes the biscuit (cookie).
|
|
|
|
|
I think it's the same cookie under a different name.
"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
|
|
|
|
|
Minor add:
I think the loop increment is wrong
I have commented out inner loop and addend two more list to the array
so the decimal count should be 5.
OK the code say Array size 4
and it misses the last array.
That should be a snap to fix...
<"TASK #ifdef FUNCTION_TEST_PROJECT int MainWindow_Bluetooth::CreateMenus_Array()79"
" index array 0 Array size 4"
" index array 1 Array size 4"
" index array 2 Array size 4"
" index array 3 Array size 4"/pre>
OK, I have plain C question about nested "loop"
My task is to loop thru two dimensional array...
The error in my code is stopping the embedded loop.
Here is a snippet of the run debug messages
here is the "problem " code
for (index_main = 0; index_main < list_array[index_array][index_main].size(); ++index_main)
What am I doing wrong in sizing the array?
Many thanks for help resolving this.
Debug
<pre lang="text">" index array 0Array size 4"
" main menus 0 SubWindow terminal (QMdiArea )main menu size 34"
" main menus 1 SubWindow hcitool (QMdiArea )main menu size 34"
" main menus 2 SubWindow bluetoothctl (QMdiArea )main menu size 34"
" main menus 3 SubWindow system (QMdiArea )main menu size 34"
ASSERT failure in QList<T>::operator[]: "index out of range", file /home/nov25-1/Qt/5.15.2/gcc_64/include/QtCore/qlist.h, line 575
12:23:02: /mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/mdi/mdi crashed.
Array;
const QStringList list_array[10]
{
{ "SubWindow terminal (QMdiArea )",
"SubWindow hcitool (QMdiArea )",
"SubWindow bluetoothctl (QMdiArea )",
"SubWindow system (QMdiArea )" },
{ "SubsubWindow bluetoothctl help (QMdiArea )",
"SubsubWindow bluetoothctl list (QMdiArea )",
"SubsubWindow bluetoothctl devices (QMdiArea )",
"SubsubWindow bluetoothctl show (QMdiArea )" },
{ "SubsubWindow hcitool (QMdiArea )",
"SubsubWindow hcitool dev (QMdiArea )",
"SubsubWindow hcitool scan (QMdiArea )",
"SubsubWindow hcitool inq (QMdiArea )"}
};
Code:
for (index_array = 0; index_array < list_array[index_array].size(); ++index_array )
{
text = " index array ";
text += QString::number(index_array);
text += "Array size ";
text += QString::number(list_array[index_array].size() );
qDebug() << text;
for (index_main = 0; index_main < list_array[index_array][index_main].size(); ++index_main)
{
text = " main menus ";
text += QString::number(index_main);
text += " ";
text += list_array[index_array][index_main];
text += "main menu size ";
text += QString::number(list_array[index_array][index_main].size());
qDebug() << text;
}
}
modified 15-Jan-24 18:16pm.
|
|
|
|