Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    need some pointers on this code


    hello all!

    i'm teaching myself QT, and i'm stuck with this part.

    can somebody point out what's wrong with this function? the file doesn't load. the manner of creating and calling functions is almost the same with Java, so i just read the class's member functions so i'll know how to call/use it.

    void MyWidget::readFile( const QString &filename )
    {
    QString readfile;
    QFileInfo fi;
    fi.setFile( "sometext.data" ); // --> this is the default data to load

    if ( fi.exists() ) {
    readfile = fi.absFilePath(); }
    else if ( !fi.exists() ) { // --> if not found, then load from another data source
    readfile = filename; }

    QFile f( readfile );
    if ( !f.open( IO_ReadOnly ) )
    return;

    QTextStream t( &f );

    while ( !t.atEnd() ) {
    .. .
    }

    f.close();
    }

    and i'm confused as when to use "->" or "." when calling a function. like, for example, in creating a widget, the tutorial's example does it like this:

    QLabel *name = new QLabel( "Name", input );
    name->setAlignment( 2 );
    lname->resize( name->sizeHint() );
    uppergrid->addWidget( name, 0, 0 );

    while in the one i made above, the example calls the function with a dot.

    thanks!
    Registered User #345074

  2. #2
    Linux Newbie
    Join Date
    Apr 2004
    Location
    Stockholm, Sweden
    Posts
    130
    I can answer one of your questions.

    "." is used when accessing a member/function or variable of a class, and the instance is declared something like this :

    my_class mClass;

    -> is used when the class is declared like this :

    my_class *mClass = new my_class();

    that is, when mClass is a pointer to an instance of the class, and not the instance itself..

  3. #3
    ahhh.. . thanks ooop! i'm used to Java, and always "." is used to call a function whether the class is instantiated or is called directly without doing the latter, since there are classes that don't allow instantiation. plus i only had 1 sem of C. i'm enjoying this Qt/C++ language so far.



    i think i have the code figured. i'll just restructure it and hope it goes well.
    Registered User #345074

  4. $spacer_open
    $spacer_close
  5. #4
    ok, the code was ok. i was just calling it in the wrong place. plus i forgot to include it in the constructor. hehehe.. . my bad!

    Registered User #345074

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •