Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6908095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:31:07+00:00 2026-05-27T08:31:07+00:00

My task is to implement JPEG encoder/decoder in Qt. I have to process jpeg

  • 0

My task is to implement JPEG encoder/decoder in Qt. I have to process jpeg markers (for example 0xFFC4 which is start of huffman table) and data between markers. I open my jpeg file using QFile class. While debugging the result is shown in picture bellow. As you can see the value in marker[0] is -1/255 and marker[1] is -40/216, and the if statement is never true I don’t know why? The code is following:

try{
        char markers[2];
        char TableData[64];
        QFile *file= new QFile( "NovaSlika.jpeg");
        if(file->open(QFile::ReadOnly )){
            while(file->read((char*)markers,sizeof(markers))){

                if(markers[0]=='255' && markers[1]=='216'){//FF i C4
                    char TableLength[2];
                    char tableMetaData;
                    file->read((char*)TableLength,sizeof(TableLength));//Read table length
                    file->read((char*)tableMetaData,sizeof(tableMetaData));//Read metadata
                    file->read((char*)TableData,sizeof(TableData));//Read data
                    break;
                }

            }
        }

Picture of debugging process is here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:31:07+00:00Added an answer on May 27, 2026 at 8:31 am

    Be careful in your while condition: read() returns

    • 0 if there is no more data.
    • -1 if there is an error, such as reading past the end.
    • # bytes read otherwise.

    You should probably do:

    while( file->read( (char*)markers, sizeof(markers) ) == 2 ) 
    

    And this line isn’t right either:

    markers[0]=='255' && markers[1]=='216'
    

    Get rid of those single quotes. (-Wall on gcc would have warned you on this). It should be:

    markers[0]==255 && markers[1]==216
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a computational intensive task which I used CUDA to implement it and
TASK : I have an existing xml document (UTF-8) which uses xml namespaces and
Task: I have a camera mounted on the end of our assembly line, which
I need to implement task which is quite common feature for RichTextEditors - take
i have just received a task to implement a software that paints over pictures
I have a task to implement service with behavior like this one. My question
My task is to implement a method that overrides the = operator. I have
I have the task to implement something similar to UIImagePickerController for displaying and selecting
I have a long running task that I need to implement on a webpage.
I have to implement a Task subclass that gracefully fails if the broker is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.