|
How to? I know the basic printing functions and using the CPrintDialog plus PRINTDLG pd,
a little sample that only prints a statement but shows what I am using:
CPrintDialog dlg(FALSE, pd.Flags);
if (dlg.DoModal() != IDOK)
{
AfxMessageBox("Abort or Unknown Printer or Printer device error");
return;
}
pd.hDC = dlg.CreatePrinterDC();
ASSERT(pd.hDC !=0);
CDC * dc = new CDC;
dc = CDC::FromHandle(pd.hDC);
int cxPage = ::GetDeviceCaps (pd.hDC, HORZRES) ;
int cyPage = ::GetDeviceCaps (pd.hDC, VERTRES) ;
sizePrn.cx = cxPage;
sizePrn.cy = cyPage;
memset(&lf, 0, sizeof(lf));
lf.lfHeight = -MulDiv(12, dc->GetDeviceCaps(LOGPIXELSY), 72);
lf.lfWeight = FW_BOLD;
lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
lf.lfQuality = PROOF_QUALITY;
lstrcpy(lf.lfFaceName, "Times New Roman");
VERIFY(font.CreateFontIndirect(&lf));
dc->SetMapMode (MM_ISOTROPIC) ;
dc->SetWindowExt ( 1000, 1000) ;
dc->SetViewportExt (cxPage / 2, -cyPage / 2) ;
dc->SetViewportOrg (cxPage / 2, cyPage / 2) ;
dc->SetTextAlign(TA_BASELINE | TA_CENTER);
dc->SetBkMode(OPAQUE);
dc->SetMapMode(MM_TEXT);
dc->PatBlt(0, 0, sizePrn.cx, sizePrn.cy, WHITENESS);
dc->LPtoDP(&sizePrn);
dc->SelectObject(&font) ;
CSize extentChar = dc ->GetTextExtent("M",1);
int nCharHeight = extentChar.cy+4;
int nCharWidth = extentChar.cx+10;
BeginWaitCursor();
CString printDate = GetMyCurDateTime();
DOCINFO docinfo;
memset(&docinfo, 0, sizeof(docinfo));
docinfo.cbSize = sizeof(docinfo);
docinfo.lpszDocName = _T("Calif Lottery Winnings");
docinfo.fwType = 0;
rc = dc->StartDocA(&docinfo);
if (rc < 0)
{
sprintf(temp, "Unable to Begin printing - Error[%d]", rc);
MessageBox(temp, NULL, MB_OK);
dc->ReleaseAttribDC();
dc->ReleaseOutputDC();
dc->DeleteTempMap();
EndWaitCursor();
DeleteDC(pd.hDC);
if(pd.hDevMode != NULL)
GlobalFree(pd.hDevMode);
if(pd.hDevNames != NULL)
GlobalFree(pd.hDevNames);
dc = 0;
return;
}
szTitle=CString("California Lottery System Printout ") + printDate;
dc -> StartPage();
dc -> SetTextAlign(TA_LEFT | TA_TOP);
dc -> TextOut(0, 0, szTitle, szTitle.GetLength() );
dc -> MoveTo( 0, nCharHeight );
dc -> LineTo(dc -> GetTextExtent(szTitle, szTitle.GetLength()).cx, nCharHeight);
nStart =1;
And goes on to print 1 page.
What I want to do is to place a non-character on a ticket but not like an 'X' but a block like a pencil fill-in mark at a specific place on the paper. I need to supply the coordinates for the mark and do that for the full page. Has anybody done something like this before? if so, give me some hints.
Thanks
Craig
|
|
|
|
|
When things get too complicate (re: printing), I create "forms" / pages / windows that match the required output; then "capture" the visual and print that in one go (as an "image" or whatever). Total WYSIWYG. Users can even "update" the "report" (if you let them).
"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
|
|
|
|
|
That is a good idea, will look into it.
|
|
|
|
|
I am debugging / modifying my working loop code and like to insert test code and "skip " the rest of large loop.
What would be a cool way to accomplish that...?
I have been "commenting out " temporary unwanted code , but that is pretty clumsy when large code blocks are commented out.
for (index = 0; index < list.size(); ++index)
{
... working code
{
...insert test block
}
... skip this working code
} loop end
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
I've never used Qt before but, this line seems odd,
for (index_array = 0; index_array < list_array[index_array].size(); ++index_array ) specifically
index_array < list_array[index_array].size() Maybe try something like
for (index_array = 0; index_array < list_array.size(); ++index_array )
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
modified 15-Jan-24 15:38pm.
|
|
|
|
|
Sorry, no go.
This is not about Qt - I no longer post questions about Qt - this is wrong forum for Qt.
This is plain C question - hence in "C..." sub forum.
In my view each loop has its stopping point.
The first - parent loop - needs to stop when it reaches the end
AND its "size" is correct (see debug message ) and I can run it bypassing the "inner " loop.
The size of inner loop is wrong - see debug messages posted.
Changing the parent loop size as suggested gets this error:
/mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/terminal_Bluetooth/mainwindow_Bluetooth.cpp:142: error: member reference base type 'const QStringList[10]' is not a structure or union
mainwindow_Bluetooth.cpp:142:52: error: member reference base type 'const QStringList[10]' is not a structure or union
for (index_array = 0; index_array < list_array.size(); ++index_array )
~~~~~~~~~~^~~~~
|
|
|
|
|
I think you've got your logic in a twist here. I think it should be
for(index_array = 0; index_array < list_array.size(); ++index_array )
{
for(index_main = 0; index_main < list_array[index_array].size(); ++index_main )
{
}
}
Additionally, note that you're calculating list_array.size() and list_array[index_array].size() multiple times. Perhaps better would be
const size_t list_max = list_array.size();
for( index_array = 0; index_array < list_max; ++index_array )
{
const size_t array_max = list_array[index_array].size();
for(index_main = 0; index_main < array_max; ++index_main)
{
}
Maybe, since you've declared list_array as const , the compiler will be able to optimize away the unneeded function calls, but speaking for myself, I find my version just a little easier to read and understand.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|