Click here to Skip to main content
15,860,844 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Why can't I print my watermark in chrome and edge? Pin
Richard MacCutchan2-Dec-20 23:05
mveRichard MacCutchan2-Dec-20 23:05 
AnswerRe: Why can't I print my watermark in chrome and edge? Pin
Randor 3-Dec-20 8:29
professional Randor 3-Dec-20 8:29 
Questionto bool or not to bool? Pin
Member 1498043325-Nov-20 8:36
Member 1498043325-Nov-20 8:36 
AnswerRe: to bool or not to bool? Pin
Mircea Neacsu25-Nov-20 9:10
Mircea Neacsu25-Nov-20 9:10 
GeneralRe: to bool or not to bool? Pin
Member 1498043325-Nov-20 17:44
Member 1498043325-Nov-20 17:44 
AnswerRe: to bool or not to bool? Pin
Mircea Neacsu25-Nov-20 17:55
Mircea Neacsu25-Nov-20 17:55 
AnswerRe: to bool or not to bool? Pin
Daniel Pfeffer26-Nov-20 7:17
professionalDaniel Pfeffer26-Nov-20 7:17 
QuestionEDITED Using template in C++ - run time error Pin
Member 1498043323-Nov-20 6:07
Member 1498043323-Nov-20 6:07 
I am trying hard to understand C++ templates.
The following test code works as expected in class constructor.
When I add SAME code to class method - which is is activated via
an event - I get "index" out of range error.

The error goes away when I include
<pre>QList<QBluetoothHostInfo> information_main = QBluetoothLocalDevice::allDevices();
= QBluetoothLocalDevice::allDevices();
in the method.

If the
QList<QBluetoothHostInfo> information_main; 

is "class variable" why do I have to "initialize " it again in the method?

The "index" is method variable (local) and is initialized to 0. - So why am I running out of index range ?

If you kindly answer the above and refrain from critiquing my coding style I would be grateful.

Thanks 






<pre lang="text"><pre lang="c++">
<pre>  // task retrive all locla BT devices
    // changed to class variable
    QList<QBluetoothHostInfo> information_main = QBluetoothLocalDevice::allDevices();
    qDebug() << "QDEBUG TRACE //11/23/2020 # of local BT detetced  " <<  information_main.count();

    // add to display
    // add test text - output
    //on_pushButton_7_clicked()
    ui->listWidget->addItem("MainWindow test # of local BT detetced  ");
    ui->listWidget->addItem("# of local BT detetced  ");
    ui->listWidget->addItem("information_main.count())");
    //TDOD add conversion

    ui->listWidget->addItem("TODO add conversion");
    // ui->listWidget->addItem( fromStdString(information_main.count());
    //information_main.first();
    // display all adapters
    int index = 0;
    do
    {
        information_main.at(index).address().toString();
        ui->listWidget->addItem("information_main.at(0).address()");
        ui->listWidget->addItem( information_main.at(index).address().toString());
        ui->listWidget->addItem(" information_main.at(0).name()");
        ui->listWidget->addItem( information_main.at(index).name());
        index++;
    }    while( index != information_main.count() );

    qDebug() << "file     " << __FILE__;
    qDebug() << "function "<<__FUNCTION__;
    qDebug() << "@line    " << __LINE__;
    qDebug()<<"TEMPORARY EXIT ";
    information_main.count();
    //exit(99);
#endif



EDITED

The purpose of the post is to identify WHY
the do-while loop works as coded in constructor and fails - run time error - when used in method.

It is , as already posted , a test code.
The task is to read the list of devices returned by

Template "list" = QBluetoothLocalDevice::allDevices();

It would be nice if contributions lead to resolve this SPECIFIC problem.
Naming variables, verifying validity of "loop index / count" , pointing out the code is
repeated in class method so far does not addresses my error usage of template.

The only answer I have - it is run time error , not a compiler error as I initially thought. Good point.

modified 25-Nov-20 23:32pm.

AnswerRe: Using template in C++ Pin
Richard MacCutchan23-Nov-20 6:25
mveRichard MacCutchan23-Nov-20 6:25 
GeneralRe: Using template in C++ Pin
Member 1498043324-Nov-20 14:34
Member 1498043324-Nov-20 14:34 
GeneralRe: Using template in C++ Pin
Dave Kreskowiak24-Nov-20 19:01
mveDave Kreskowiak24-Nov-20 19:01 
GeneralRe: Using template in C++ Pin
Richard MacCutchan24-Nov-20 22:13
mveRichard MacCutchan24-Nov-20 22:13 
GeneralRe: Using template in C++ Pin
Member 1498043325-Nov-20 6:58
Member 1498043325-Nov-20 6:58 
GeneralRe: Using template in C++ Pin
jeron125-Nov-20 7:23
jeron125-Nov-20 7:23 
GeneralRe: Using template in C++ Pin
Richard MacCutchan25-Nov-20 7:42
mveRichard MacCutchan25-Nov-20 7:42 
GeneralRe: Using template in C++ Pin
Member 1498043325-Nov-20 8:53
Member 1498043325-Nov-20 8:53 
GeneralRe: Using template in C++ Pin
Richard MacCutchan25-Nov-20 9:21
mveRichard MacCutchan25-Nov-20 9:21 
AnswerRe: Using template in C++ Pin
jeron123-Nov-20 6:41
jeron123-Nov-20 6:41 
GeneralRe: Using template in C++ Pin
Member 1498043324-Nov-20 14:27
Member 1498043324-Nov-20 14:27 
GeneralRe: Using template in C++ Pin
jeron124-Nov-20 14:42
jeron124-Nov-20 14:42 
GeneralRe: Using template in C++ Pin
Member 1498043325-Nov-20 6:43
Member 1498043325-Nov-20 6:43 
GeneralRe: Using template in C++ Pin
Richard MacCutchan25-Nov-20 7:57
mveRichard MacCutchan25-Nov-20 7:57 
GeneralRe: Using template in C++ Pin
Victor Nijegorodov25-Nov-20 9:28
Victor Nijegorodov25-Nov-20 9:28 
AnswerRe: EDITED Using template in C++ - run time error Pin
Member 1498043325-Nov-20 17:39
Member 1498043325-Nov-20 17:39 
GeneralRe: EDITED Using template in C++ - run time error Pin
Richard MacCutchan26-Nov-20 0:05
mveRichard MacCutchan26-Nov-20 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.