views:

396

answers:

2

Hi, I am trying to keep a stream to a file /dev/fb0 (linux framebuffer) open throughout several Qt member functions. The goal is to use a myscreen::connect function to open up the framebuffer

bool myscreen::connect()
{
std::fstream myscreen_Fb;
myscreen_Fb.open("/dev/fb0")
QImage* image;
image = new QImage(w, h, QImage::Format_RGB888);
QScreen::data = image->bits();
}

This would ideally open the frame buffer and create a new QImage to act as a memory buffer for the data being written to the screen. Then my "image" would point to the first visible pixel (memory) on the screen through the bits() function. I have to implement this because my hardware does not support the default memory mapping.

I would then like to blit it to the screen with:

void myscreen::blit(const QImage &img, const QPoint &topLeft, const QRegion &region)
{

QScreen::blit(img, topLeft, region);
write(myscreen_Fb, image.bits(), image.size());
}

I cant seem to get the pointer to the first visible pixel open to use and get complaints from GCC about myscreen_Fb not being declared in the scope. Any ideas?

update

I made the changes suggested and declared the function in the class but get this error which is driving me crazy.

error: expected constructor, destructor, or type conversion before '.' token

It refers to the line which contains:

vopuscreenFd.open("/dev/fb0", fstream::out);

Bryce

+5  A: 

You declared myscreen_Fb in the scope of only the "connect" function. Either make it a member of the myscreen class, or even better just pass it as an argument to the "blit" function.

Chris Arguin
I did notice that eventually. I am trying to open the file and set the pointer to the first framebuffer address inside the class but not in any member functions which I believe is valid but not totally sure, I seem to get numerous errors but working through them.
bryce
+1  A: 

That is because myscreen_Fb is, in fact, not declared in the scope of the blit function. Here you declared it in the connect() function.

Declare myscreen_Fb as a member variable of the myscreen class. It will be accessible to all functions in that instance of the class.

class myscreen
{
  public:
     myscreen( void );
    ~myscreen( void );

    bool
    connect  ( void );

    void 
    blit     ( const QImage &img, 
               const QPoint &topLeft, 
               const QRegion &region)

  private: 
    std::fstream myscreen_Fb;
};

In relation to this question: "I cant seem to get the pointer to the first visible pixel open to use", what exactly do you mean here? All I can presume is that you mean to use blit using the image ptr you created within connect, which is also not yet a member variable, so perhaps you want to do this:

bool myscreen::connect()
{
    std::fstream myscreen_Fb;
    myscreen_Fb.open("/dev/fb0")
    QImage* image;
    image = new QImage(w, h, QImage::Format_RGB888);
    //QScreen::data = image->bits();   //don't need this?
    blit( image, "topleft ref", "region ref");     //add this, replacing 
                                                   // "topleft ref" and
                                                   // "region ref" with correct 
                                                   // values you've pulled
}

and the write function within myscreen::blit get's the ptr to the first pixel. I am making a lot of presumptions here because the question is a bit unclear.

BuckFilledPlatypus
Thanks! I'll take a look at it and see what can be done. As for the blit operation, that needs to take place whenever there is a change on the screen so its not really suited for the connect function since connect isn't meant to be run several times per second! Hope that helps and I'll update accordingly.
bryce