I believe that I am doing something very wrong with my image buttons. I want to do something as simple as making them change its image whenever I hover over the button or by pressing it. Stylesheets are a bit ambiguous at the moment for me.
Here is a code snip where I think I am doing wrong with it:
border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;
hover:{border-image: url(:/Data/buttonNUC_Hover.png) 0 0 0 0 stretch stretch;};
pressed: {border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;};
Does anyone has any idea on what I can do?
Another thing that I tried, but to no avail.
void MainWindow::on_nucButton_pressed()
{
ui->nucButton->setStyleSheet("QLineEdit {border-image: url(:/Data/buttonNUC_Pressed.png) 0 0 0 0 stretch stretch;}");
// printf("Work?\n");
}
Try this
ui->nucButton->setStyleSheet("QLineEdit {border-image: url(:/Data/buttonNUC_Pressed.png) 0 0 0 0 stretch stretch;}"
"QLineEdit:hover {border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;}"
"QLineEdit:pressed {border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;}");
Solved it - just copy pasted the old project code into a new project and everything worked. For some reason my Qt project got bugged and it didn't let me do it.
I am working on a unix machine. and I have a list of names in .eps file format. I know I can easily grep show lines to extract my names but they're not in the same order as in the figure. is there a way to extract names from the figure while preserving the order?
example:
/ArialMT-ISOLatin1 findfont
32 scalefont
setfont
0 0 0 setrgbcolor
newpath
0 0 moveto
(King James) show
grestore
grestore
grestore
0 0 0 setrgbcolor
[] 0 setdash
5 setlinewidth
0 setlinejoin
1 setlinecap
newpath
-1013.087 5437.645 moveto
-574.44269 5148.3467 lineto
stroke
0 0 0 setrgbcolor
[] 0 setdash
5 setlinewidth
0 setlinejoin
1 setlinecap
newpath
-801.10602 5042.689 moveto
-683.66547 4973.3872 lineto
stroke
0 0 0 setrgbcolor
[] 0 setdash
5 setlinewidth
0 setlinejoin
0 setlinecap
newpath
-764.50114 5103.5574 moveto
-789.24211 5063.1816 -813.3093 5022.3968 -836.69272 4981.22 curveto
stroke
gsave [0.8480481 -0.52991926 0.52991926 0.8480481 -3204.0386 27.010243]
concat
gsave [1 0 0 -1 -1554.9214 5600.4102] concat
gsave
/ArialMT-ISOLatin1 findfont
32 scalefont
setfont
0 0 0 setrgbcolor
newpath
0 0 moveto
(M. L. King) show
...
M.L.King should go before King James but could I do this by exploiting the coordinate system?
thnx
First, I wanted to suggest to keep track of movements ie where the PostScript interpreter is putting the text, but that can be tricky since postscript is a fully fledged programming language. Another approach is to annotate your .eps files:
open a file with the 'open' command
for every show
a. get the current coordianates by 'currentpoint'. this leaves the coordinates on the stack
b. 'write' those two values into your file (as a .csv perhaps?) and the text which is going to be shown
close the file with 'closefile'
Run your annotated .eps file through a PS interpreter. Sort the generated file on the coordinates with the Unix 'sort' command, don't forget the -n option for both keys (ie y coordinate and x coordinate). And you are done.
I have a file with a few blocks that look like this in a file (and in a variable, at this point in the program).
Vlan2 is up, line protocol is up
....
reliability 255/255, txload 1/255, rxload 1/255^M
....
Last clearing of "show interface" counters 49w5d
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
....
L3 out Switched: ucast: 17925 pkt, 23810209 bytes mcast: 0 pkt, 0 bytes
33374 packets input, 13154058 bytes, 0 no buffer
Received 926 broadcasts (0 IP multicasts)
0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
3094286 packets output, 311981311 bytes, 0 underruns
0 output errors, 0 interface resets
0 output buffer failures, 0 output buffers swapped out
Here's a second block, to show you how the blocks can slightly vary:
port-channel86 is down (No operational members)
...
reliability 255/255, txload 1/255, rxload 1/255
...
Last clearing of "show interface" counters 31w2d
...
RX
147636 unicast packets 0 multicast packets 0 broadcast packets
84356 input packets 119954232 bytes
0 jumbo packets 0 storm suppression packets
0 runts 0 giants 0 CRC 0 no buffer
0 input error 0 short frame 0 overrun 0 underrun 0 ignored
0 watchdog 0 bad etype drop 0 bad proto drop 0 if down drop
0 input with dribble 0 input discard
0 Rx pause
TX
147636 unicast packets 0 multicast packets 0 broadcast packets
84356 output packets 119954232 bytes
0 jumbo packets
0 output error 0 collision 0 deferred 0 late collision
0 lost carrier 0 no carrier 0 babble 0 output discard
0 Tx pause
0 interface resets
I want to pick out certain data elements from each block, which may or may not exist in each block. For example, in the first block I posted I may want to know that there are 0 runts, 0 input errors and 0 overrun. In the second block, I might want to know that there are 0 jumbo packets, collisions, etc. If a given query isn't in the block, it's acceptable to just return na, as this is designed to be processed uniformly.
Each block is structured in a similar way to the two I posted; newlines and spaces delimiting some entries, commas delimiting others.
I have a few ideas as to how this might work. I'm unaware if there is any kind of "look back" function in Perl, but I could attempt to look for the field names (runts, "input errors", etc) and then grab the previous integer; that seems like it would be the most elegant solution for this, but I'm unsure if it's possible.
Currently, I'm doing this in Perl. Each "block" that I'm processing is actually several of these blocks (separated by double newlines). It doesn't have to be done in a single regular expressions; I believe it can be done by applying several regular expressions per block. Performance is not really a factor, as this script will run maybe once per hour.
My goal is to get all of this into a .csv file (or some other data format that's easily graphable) in an automated fashion.
Any ideas?
Edit: example output in CSV as I mentioned, which would be written line by line (for multiple entries like this) to a file as the end result. If a particular entry isn't found in the block, it is marked na in the corresponding line:
interface_name,txload,rxload,last_clearing,input_queue,output_drops,runts,....
vlan2,1,1,49w5d,0-75-0-0,0,0,....
port-channel86,1,1,31w2d,na,na,0,...
Simple hash of properties and numbers.
sub extract {
my ($block) = #_;
my %r;
while ($block =~ /(?<num>\d+) \s (?<name>[A-Za-z\s]+)/gmsx) {
my $name = $+{name};
my $num = $+{num};
$name =~ s/\A \s+//msx;
$name =~ s/\s+ \z//msx;
$r{$name} = $num;
}
return %r;
}
my $block = <<'';
Vlan2 is up, line protocol is up
⋮
my $block2 = <<'';
port-channel86 is down (No operational members)
⋮
use Data::Dumper qw(Dumper);
print Dumper {extract $block};
print Dumper {extract $block2};
I don't think a single regex could do it, nor would I want to support it if it could.
Using multiple regexes, you could easily use something like:
(\d+) runts
(\d+) input errors
...etc...
A simple array of property names and a loop could solve this pretty quickly and with very little fuss.
If you can strip down the input to smaller chunks with some preprocessing, you would be less likely to get false positives.
Here is one way to do it in awk, but this needs lots of tweak to be perfect.
But again, use SNMP.
awk '{
printf $1
for (i=1;i<=NF;i++) {
if ($i" "$(i+1)~/Input queue:/) printf ",%s",$(i+2)
if ($i~/runts/) printf ",%s",$(i-1)
if ($i~/multicast,/) printf ",%s",$(i-1)
}
print ""
}' RS="swapped out" file
i wrote a kernelspace driver for a USB-device. If it is connected it mounts to /dev/myusbdev0 for example.
Via command line with echo -en "command" > /dev/myusbdev0 i can send commands to the device and read results with cat /dev/myusbdev0.
Ok, now i have to write a C++ program. At first i would open the device file for read/write with:
int fd = open("/dev/echo", O_RDRW);
After that a cmd will be send to get the device working:
char cmd[] = { "\x02sEN LMDscandata 1\x03" };
write(fd, cmd, sizeof(cmd));
Now i get to the part i dont now how to handle yet. i now need to read from the device, as its keeping on sending me data continously. this data i need to read and parse now ...
char buf[512];
read(fd, buf, sizeof(buf);
The data looks like following, each one starts with \x02 and ends with \x03, they are not always the same size:
sRA LMDscandata 1 1 89A27F 0 0 343 347 27477BA9 2747813B 0 0 7 0 0
1388 168 0 1 DIST1 3F800000 00000000 186A0 1388 15 8A1 8A5 8AB 8AC 8A6
8AC 8B6 8C8 8C2 8C9 8CB 8C4 8E4 8E1 8EB 8E0 8F5 908 8FC 907 906 0 0 0
0 0 0 All Values are separated with a 20hex {SPC}
it think i need some kind of while loop to continiously read the data from an \x02 until i read a \x03.
if i have a complete scan, i need to parse this ascii message in its seperate parts (some variables uint_16, uint_8, enum_16, ...).
any idea how i can read a complete scan into a buf[] and then parse its components out?
As you say the device is sending continiously, i would recommend adding a queue to hold the chunks coming in, and some dispatching that takes out parts of the queue, i.e. x02 to x03, decoupling the work that is done from receiving chunks.
Furthermore you can have then single objects handling one complete block from x02 to x03, perhaps threaded (makes sense with the information given).
device => chunk reader => input queue => inputer reader => data handling
hope this helps
Can any one tell me how to write a simple C++ code to export my data(from variable) into PDF file without using any external libraries or utilities?
Use fprintf and write to a file, conforming to the PDF file format.
Specifically look in Appendix G. You might be able to get away with some very simple transformations and produce a readable PDF file.
Without using a PDF library your best way might be to create a simple PDF with sample text using some other application (eg OpenOffice). Then use this as a basis for the boiler plate and have you C++ code insert your own text in place. Note that PDF is line orientated so each new line of text has to be explicitly placed at the correct position.
For anything other than very simple output this is going to be tricky without fully understanding the PDF spec
Can any one tell me how to write a simple C++ code to export my data(from variable) into PDF file without using any external libraries or utilities?
No. PDF files are complicated. To read and write them, your code is going to be complicated. Normally, you could use an external library to hide that complexity, but if you don't want to do that, then your code is going to have to contain the complexity. And then it will not be simple.
You're asking for the impossible. You're asking to perform a complex task without doing anything complex yourself, and without relying on anyone else to do something complex for you.
But someone is going to have to do it.
I'm currently using ZendPDF right now, and I have created a test pdf file that looked like this when viewed as text. When I changed the text "This is a test" to "This is a super test" in the pdf file itself, I was able to change the final pdf file and it opened in foxit. So, copy this and use C++ to replace the string with what you want. I was also able to make new text appear with just a text editor by copying that F1 14 Tf stuff.
The php used to output this text is
<?php
require("inc/function.inc.php");
// start authorization check
require("inc/authcheckhdr.inc.php");
$pdf = new Zend_Pdf();
// Fetch the first page so you can draw on top of it.
$page = $pdf->pages[0] = $pdf->newPage('A4');
// Set font and text color.
$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 14);
$page->setFillColor(new Zend_Pdf_Color_HTML('black'));
// Draw some text on top of the page at x,y
$page->drawText('This is a test', 72, 720);
// More drawing commands...
// Save the resulting PDF document. OR
$pdf->save('result.pdf');
// Render the resulting PDF and send it to the browser
$pdfDocument = $pdf->render();
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=result.pdf");
echo $pdfDocument;
?>
The pdf file is...
%PDF-1.4
%âãÏÓ
1 0 obj
<</Type /Catalog /Version /1.4 /Pages 2 0 R /Names 7 0 R >>
endobj
2 0 obj
<</Type /Pages /Kids [3 0 R ] /Count 1 >>
endobj
3 0 obj
<</Type /Page /LastModified (D:20091231114504-08'00') /Resources <</ProcSet [/Text /PDF ] /Font <</F1 8 0 R >> >> /MediaBox [0 0 595 842 ]
/Contents [4 0 R ] /Parent 2 0 R >>
endobj
4 0 obj
<</Length 50 >>
stream
/F1 14 Tf
0 g
BT
72 620 Td
(This is a test) Tj
ET
/F1 14 Tf
0 g
BT
72 720 Td
(This is a super test) Tj
ET
endstream
endobj
5 0 obj
[]
endobj
6 0 obj
<</Names 5 0 R >>
endobj
7 0 obj
<</Dests 6 0 R >>
endobj
8 0 obj
<</Type /Font /Encoding /WinAnsiEncoding /Subtype /Type1 /BaseFont /Helvetica >>
endobj
xref
0 9
0000000000 65535 f
0000000015 00000 n
0000000091 00000 n
0000000149 00000 n
0000000341 00000 n
0000000441 00000 n
0000000460 00000 n
0000000494 00000 n
0000000528 00000 n
trailer
<</ID [<65386133343365653231383339346131> <64663632306233616663343536616332> ] /Size 9 /Root 1 0 R >>
startxref
625
%%EOF
...without using any external
libraries or utilities?
that is a bit of a problem... If you are using QT you can do it... What is your setup?