void readFromShMem()
{
int tOTL=0;
int tONL=0;
int tSNL=0;
int tSLL=0;
int tIDL=0;
int tMDL=0;
int readingLength;
//lock the file for writing
memset (&lock, 0, sizeof(lock));
lock.l_type = F_WRLCK;
fcntl (fd, F_SETLKW, &lock);
//struct cursStruct *cursVar=(cursStruct*)((char*)file_memory + 0x4);
struct ShMem *infoVar=(ShMem*)((char*)file_memory);
tOTL = infoVar->oTL;
tONL = infoVar->oNL;
tSNL = infoVar->sNL;
tSLL = infoVar->sLL;
tIDL = infoVar->iDL;
tMDL = infoVar->mDL;
readingLength = tOTL + tONL + tSNL + tSLL + tIDL + tMDL ;
char readingStrs[readingLength];
printf("reading length = %d\n", readingLength);
printf("the infoVar->oAndS_str reading points to = %p\n",&(infoVar->oAndS_str));
memcpy(&readingStrs, &(infoVar->oAndS_str), readingLength);
printf("readingStrs contains after = %s\n",readingStrs);
//unlock the file to allow access
lock.l_type = F_UNLCK;
fcntl (fd, F_SETLKW, &lock);
char tOT[tOTL]; memcpy(tOT,readingStrs,tOTL);
printf("tOTL = %d and oT ptr = %p\n", tOTL, readingStrs);
char tON[tONL]; memcpy(tON,(readingStrs+tOTL),tONL);
printf("tONL = %d and oN ptr = %p\n", tONL, (readingStrs+tOTL));
char tSN[tSNL]; memcpy(tSN,(readingStrs+tOTL+tONL),tSNL);
printf("tSNL = %d and sN ptr = %p\n", tSNL, (readingStrs+tOTL+tONL));
char tSL[tSLL]; memcpy(tSL,(readingStrs+tOTL+tONL+tSNL),tSLL);
printf("tSLL = %d and sL ptr = %p\n", tSLL, (readingStrs+tOTL+tONL+tSNL));
char tID[tIDL]; memcpy(tID,(readingStrs+tOTL+tONL+tSNL+tSLL),tIDL);
printf("tIDL = %d and iD ptr = %p\n", tIDL, (readingStrs+tOTL+tONL+tSNL+tSLL));
char tMD[tMDL]; memcpy(tMD,(readingStrs+tOTL+tONL+tSNL+tSLL+tIDL),tMDL);
printf("tMDL = %d and mD ptr = %p\n", tMDL, (readingStrs+tOTL+tONL+tSNL+tSLL+tIDL));
//the printf's below output the right values on console
printf("oT = %.8s.\n",tOT);
printf("oN = %.4s.\n",tON);
printf("sN = %.4s.\n",tSN);
printf("sL = %.5s.\n",tSL);
printf("iD = %.10s.\n",tID);
printf("mD = %.9s.\n",tMD);
//but the QString values below do not output the right values when they are 'setText'd' in QLabels.
operatorTel
= QString::fromLocal8Bit((const char*)tOT
);
operatorName
= QString::fromLocal8Bit((const char*)tON
);
stationNum
= QString::fromLocal8Bit((const char*)tSN
);
stationLoc
= QString::fromLocal8Bit((const char*)tSL
);
installationDate
= QString::fromLocal8Bit((const char*)tID
);
maintenanceDate
= QString::fromLocal8Bit((const char*)tMD
);
}
void readFromShMem()
{
int tOTL=0;
int tONL=0;
int tSNL=0;
int tSLL=0;
int tIDL=0;
int tMDL=0;
int readingLength;
//lock the file for writing
memset (&lock, 0, sizeof(lock));
lock.l_type = F_WRLCK;
fcntl (fd, F_SETLKW, &lock);
//struct cursStruct *cursVar=(cursStruct*)((char*)file_memory + 0x4);
struct ShMem *infoVar=(ShMem*)((char*)file_memory);
tOTL = infoVar->oTL;
tONL = infoVar->oNL;
tSNL = infoVar->sNL;
tSLL = infoVar->sLL;
tIDL = infoVar->iDL;
tMDL = infoVar->mDL;
readingLength = tOTL + tONL + tSNL + tSLL + tIDL + tMDL ;
char readingStrs[readingLength];
printf("reading length = %d\n", readingLength);
printf("the infoVar->oAndS_str reading points to = %p\n",&(infoVar->oAndS_str));
memcpy(&readingStrs, &(infoVar->oAndS_str), readingLength);
printf("readingStrs contains after = %s\n",readingStrs);
//unlock the file to allow access
lock.l_type = F_UNLCK;
fcntl (fd, F_SETLKW, &lock);
char tOT[tOTL]; memcpy(tOT,readingStrs,tOTL);
printf("tOTL = %d and oT ptr = %p\n", tOTL, readingStrs);
char tON[tONL]; memcpy(tON,(readingStrs+tOTL),tONL);
printf("tONL = %d and oN ptr = %p\n", tONL, (readingStrs+tOTL));
char tSN[tSNL]; memcpy(tSN,(readingStrs+tOTL+tONL),tSNL);
printf("tSNL = %d and sN ptr = %p\n", tSNL, (readingStrs+tOTL+tONL));
char tSL[tSLL]; memcpy(tSL,(readingStrs+tOTL+tONL+tSNL),tSLL);
printf("tSLL = %d and sL ptr = %p\n", tSLL, (readingStrs+tOTL+tONL+tSNL));
char tID[tIDL]; memcpy(tID,(readingStrs+tOTL+tONL+tSNL+tSLL),tIDL);
printf("tIDL = %d and iD ptr = %p\n", tIDL, (readingStrs+tOTL+tONL+tSNL+tSLL));
char tMD[tMDL]; memcpy(tMD,(readingStrs+tOTL+tONL+tSNL+tSLL+tIDL),tMDL);
printf("tMDL = %d and mD ptr = %p\n", tMDL, (readingStrs+tOTL+tONL+tSNL+tSLL+tIDL));
//the printf's below output the right values on console
printf("oT = %.8s.\n",tOT);
printf("oN = %.4s.\n",tON);
printf("sN = %.4s.\n",tSN);
printf("sL = %.5s.\n",tSL);
printf("iD = %.10s.\n",tID);
printf("mD = %.9s.\n",tMD);
//but the QString values below do not output the right values when they are 'setText'd' in QLabels.
operatorTel = QString::fromLocal8Bit((const char*)tOT);
operatorName = QString::fromLocal8Bit((const char*)tON);
stationNum = QString::fromLocal8Bit((const char*)tSN);
stationLoc = QString::fromLocal8Bit((const char*)tSL);
installationDate = QString::fromLocal8Bit((const char*)tID);
maintenanceDate = QString::fromLocal8Bit((const char*)tMD);
}
To copy to clipboard, switch view to plain text mode
Bookmarks