Click here to Skip to main content
14,742,675 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Why can't I print my watermark in chrome and edge? Pin
Richard MacCutchan3-Dec-20 0:05
mveRichard MacCutchan3-Dec-20 0:05 
AnswerRe: Why can't I print my watermark in chrome and edge? Pin
Randor 3-Dec-20 9:29
professional Randor 3-Dec-20 9:29 
Questionto bool or not to bool? Pin
Member 1498043325-Nov-20 9:36
MemberMember 1498043325-Nov-20 9:36 
AnswerRe: to bool or not to bool? Pin
Mircea Neacsu25-Nov-20 10:10
mvaMircea Neacsu25-Nov-20 10:10 
GeneralRe: to bool or not to bool? Pin
Member 1498043325-Nov-20 18:44
MemberMember 1498043325-Nov-20 18:44 
AnswerRe: to bool or not to bool? Pin
Mircea Neacsu25-Nov-20 18:55
mvaMircea Neacsu25-Nov-20 18:55 
AnswerRe: to bool or not to bool? Pin
Daniel Pfeffer26-Nov-20 8:17
professionalDaniel Pfeffer26-Nov-20 8:17 
QuestionEDITED Using template in C++ - run time error Pin
Member 1498043323-Nov-20 7:07
MemberMember 1498043323-Nov-20 7: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 7:25
mveRichard MacCutchan23-Nov-20 7:25 
GeneralRe: Using template in C++ Pin
Member 1498043324-Nov-20 15:34
MemberMember 1498043324-Nov-20 15:34 
GeneralRe: Using template in C++ Pin
Dave Kreskowiak24-Nov-20 20:01
mveDave Kreskowiak24-Nov-20 20:01 
GeneralRe: Using template in C++ Pin
Richard MacCutchan24-Nov-20 23:13
mveRichard MacCutchan24-Nov-20 23:13 
GeneralRe: Using template in C++ Pin
Member 1498043325-Nov-20 7:58
MemberMember 1498043325-Nov-20 7:58 
GeneralRe: Using template in C++ Pin
jeron125-Nov-20 8:23
Memberjeron125-Nov-20 8:23 
GeneralRe: Using template in C++ Pin
Richard MacCutchan25-Nov-20 8:42
mveRichard MacCutchan25-Nov-20 8:42 
GeneralRe: Using template in C++ Pin
Member 1498043325-Nov-20 9:53
MemberMember 1498043325-Nov-20 9:53 
GeneralRe: Using template in C++ Pin
Richard MacCutchan25-Nov-20 10:21
mveRichard MacCutchan25-Nov-20 10:21 
AnswerRe: Using template in C++ Pin
jeron123-Nov-20 7:41
Memberjeron123-Nov-20 7:41 
GeneralRe: Using template in C++ Pin
Member 1498043324-Nov-20 15:27
MemberMember 1498043324-Nov-20 15:27 
GeneralRe: Using template in C++ Pin
jeron124-Nov-20 15:42
Memberjeron124-Nov-20 15:42 
GeneralRe: Using template in C++ Pin
Member 1498043325-Nov-20 7:43
MemberMember 1498043325-Nov-20 7:43 
GeneralRe: Using template in C++ Pin
Richard MacCutchan25-Nov-20 8:57
mveRichard MacCutchan25-Nov-20 8:57 
GeneralRe: Using template in C++ Pin
Victor Nijegorodov25-Nov-20 10:28
MemberVictor Nijegorodov25-Nov-20 10:28 
AnswerRe: EDITED Using template in C++ - run time error Pin
Member 1498043325-Nov-20 18:39
MemberMember 1498043325-Nov-20 18:39 
GeneralRe: EDITED Using template in C++ - run time error Pin
Richard MacCutchan26-Nov-20 1:05
mveRichard MacCutchan26-Nov-20 1: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.